cleaned more date code, setup testing for stats, renamed plugin and info
cleaned more date code, setup testing for stats, renamed plugin and info
This commit is contained in:
parent
0e6751f093
commit
f77466b8a2
5 changed files with 45 additions and 12 deletions
4
main.ts
4
main.ts
|
|
@ -3,12 +3,10 @@ import { ExampleSettingsTab } from "./settings";
|
||||||
import { ExampleView, VIEW_TYPE_EXAMPLE} from "./view"
|
import { ExampleView, VIEW_TYPE_EXAMPLE} from "./view"
|
||||||
|
|
||||||
interface ExamplePluginSettings {
|
interface ExamplePluginSettings {
|
||||||
dateFormat: string
|
|
||||||
userID: string
|
userID: string
|
||||||
apiToken: string
|
apiToken: string
|
||||||
}
|
}
|
||||||
const DEFAULT_SETTINGS: Partial<ExamplePluginSettings> = {
|
const DEFAULT_SETTINGS: Partial<ExamplePluginSettings> = {
|
||||||
dateFormat: "YYYY-MM-DD",
|
|
||||||
userID: "",
|
userID: "",
|
||||||
apiToken: ""
|
apiToken: ""
|
||||||
}
|
}
|
||||||
|
|
@ -23,7 +21,7 @@ export default class ExamplePlugin extends Plugin {
|
||||||
VIEW_TYPE_EXAMPLE,
|
VIEW_TYPE_EXAMPLE,
|
||||||
(leaf) => (this.view = new ExampleView(leaf, this))
|
(leaf) => (this.view = new ExampleView(leaf, this))
|
||||||
);
|
);
|
||||||
this.addRibbonIcon("dice", "Activate view", () => { //activate view
|
this.addRibbonIcon("dice", "Open Habitica Pane", () => { //activate view
|
||||||
this.activateView();
|
this.activateView();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"id": "test-plugin",
|
"id": "obsidian-habitica-integration",
|
||||||
"name": "Test Plugin",
|
"name": "AAA Obsidian Habitica Integration",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"minAppVersion": "0.9.12",
|
"minAppVersion": "0.9.12",
|
||||||
"description": "This is a sample plugin for Obsidian. This plugin demonstrates some of the capabilities of the Obsidian API.",
|
"description": "This plugin helps integrate Habitica user tasks and stats into Obsidian",
|
||||||
"author": "Leoh",
|
"author": "Leoh and Ran",
|
||||||
"authorUrl": "",
|
"authorUrl": "",
|
||||||
"isDesktopOnly": false
|
"isDesktopOnly": false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "test-plugin",
|
"name": "obsidian-habitica-integration",
|
||||||
"version": "0.12.0",
|
"version": "0.12.0",
|
||||||
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
|
"description": "This plugin allows for Habitica integration into Obsidian",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "rollup --config rollup.config.js -w",
|
"dev": "rollup --config rollup.config.js -w",
|
||||||
|
|
|
||||||
25
view/App.tsx
25
view/App.tsx
|
|
@ -1,5 +1,5 @@
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { getTasks } from "./habiticaAPI"
|
import { getTasks, getStats } from "./habiticaAPI"
|
||||||
import TodoItem from "./TodoItem"
|
import TodoItem from "./TodoItem"
|
||||||
|
|
||||||
let username = ""
|
let username = ""
|
||||||
|
|
@ -33,17 +33,36 @@ class App extends React.Component<any,any> {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
getStats(username, credentials)
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(
|
||||||
|
result => {
|
||||||
|
this.setState({
|
||||||
|
isLoaded: true,
|
||||||
|
stats: result.data
|
||||||
|
})
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
this.setState({
|
||||||
|
isLoaded: true,
|
||||||
|
error
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
render(){
|
render(){
|
||||||
const { error, isLoaded, tasks } = this.state;
|
const { error, isLoaded, tasks, stats } = this.state;
|
||||||
if (error) {
|
if (error) {
|
||||||
return <div>Error: {error.message}</div>;
|
return <div>Error: {error.message}</div>;
|
||||||
} else if (!isLoaded) {
|
} else if (!isLoaded) {
|
||||||
return <div>Loading...</div>;
|
return <div>Loading...</div>;
|
||||||
} else {
|
} else {
|
||||||
const listItems = tasks.map((tasks: any) =>
|
const listItems = tasks.map((tasks: any) =>
|
||||||
|
<div>
|
||||||
<TodoItem key={tasks.id} task={tasks}/>
|
<TodoItem key={tasks.id} task={tasks}/>
|
||||||
|
<p>{stats}</p>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<ul>{listItems}</ul>
|
<ul>{listItems}</ul>
|
||||||
|
|
|
||||||
|
|
@ -14,3 +14,19 @@ export async function getTasks(username: string, credentials: string){
|
||||||
})
|
})
|
||||||
return (response)
|
return (response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getStats(username: string, credentials: string){
|
||||||
|
const url = "https://habitica.com/export/userdata.json"
|
||||||
|
const response = fetch(url, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"x-client": username.concat("-testAPI"),
|
||||||
|
"x-api-user": username,
|
||||||
|
"x-api-key": credentials,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
console.log(response)
|
||||||
|
console.log("stats above")
|
||||||
|
return (response)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue