Initial Commit
This commit is contained in:
parent
b2d4fecec3
commit
59cb8f1d70
7 changed files with 101 additions and 7 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -12,3 +12,6 @@ main.js
|
||||||
|
|
||||||
# obsidian
|
# obsidian
|
||||||
data.json
|
data.json
|
||||||
|
|
||||||
|
#vscode
|
||||||
|
.vscode
|
||||||
6
ReactView.tsx
Normal file
6
ReactView.tsx
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
import * as React from "react";
|
||||||
|
import App from "./view/App";
|
||||||
|
|
||||||
|
export const ReactView = () => {
|
||||||
|
return <App />;
|
||||||
|
};
|
||||||
12
styles.css
12
styles.css
|
|
@ -1,2 +1,14 @@
|
||||||
/* Empty. change later */
|
/* Empty. change later */
|
||||||
|
|
||||||
|
.book {
|
||||||
|
border: 1px solid var(--background-modifier-border);
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book__title {
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book__author {
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
@ -3,8 +3,9 @@
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"inlineSourceMap": true,
|
"inlineSourceMap": true,
|
||||||
"inlineSources": true,
|
"inlineSources": true,
|
||||||
"module": "ESNext",
|
"module": "esnext",
|
||||||
"target": "es6",
|
"jsx": "react",
|
||||||
|
"target": "es2017",
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
|
|
|
||||||
15
view.ts
15
view.ts
|
|
@ -1,4 +1,8 @@
|
||||||
import { ItemView,WorkspaceLeaf } from "obsidian";
|
import { ItemView,WorkspaceLeaf } from "obsidian";
|
||||||
|
import * as React from "react";
|
||||||
|
import * as ReactDOM from "react-dom";
|
||||||
|
import { ReactView } from "./ReactView";
|
||||||
|
|
||||||
|
|
||||||
export const VIEW_TYPE_EXAMPLE = "example-view"
|
export const VIEW_TYPE_EXAMPLE = "example-view"
|
||||||
|
|
||||||
|
|
@ -16,12 +20,13 @@ export class ExampleView extends ItemView {
|
||||||
}
|
}
|
||||||
|
|
||||||
async onOpen() {
|
async onOpen() {
|
||||||
const container = this.containerEl.children[1];
|
ReactDOM.render(
|
||||||
container.empty()
|
React.createElement(ReactView),
|
||||||
container.createEl("h4", {text: "Example View"});
|
this.containerEl.children[1]
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async onClose(){
|
async onClose(){
|
||||||
|
ReactDOM.unmountComponentAtNode(this.containerEl.children[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
51
view/App.tsx
Normal file
51
view/App.tsx
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
import * as React from "react";
|
||||||
|
import { getTasks } from "./habiticaAPI"
|
||||||
|
|
||||||
|
const username = "ebbdcbab-e0dc-404b-aa50-9824f0678adf"
|
||||||
|
const credentials = "bed67d72-63cc-479c-88d3-8845569b04f8"
|
||||||
|
|
||||||
|
class App extends React.Component<any,any> {
|
||||||
|
constructor(props: any) {
|
||||||
|
super(props)
|
||||||
|
this.state = {
|
||||||
|
isLoaded: false,
|
||||||
|
tasks: ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
componentDidMount() {
|
||||||
|
getTasks(username, credentials)
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(
|
||||||
|
result => {
|
||||||
|
console.log(result.data)
|
||||||
|
this.setState({
|
||||||
|
isLoaded: true,
|
||||||
|
tasks: result.data
|
||||||
|
})
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
this.setState({
|
||||||
|
isLoaded: true,
|
||||||
|
error
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
render(){
|
||||||
|
const { error, isLoaded, tasks } = this.state;
|
||||||
|
if (error) {
|
||||||
|
return <div>Error: {error.message}</div>;
|
||||||
|
} else if (!isLoaded) {
|
||||||
|
return <div>Loading...</div>;
|
||||||
|
} else {
|
||||||
|
const listItems = tasks.map((tasks: any) =>
|
||||||
|
<li>{tasks.text}</li>
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<ul>{listItems}</ul>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default App
|
||||||
16
view/habiticaAPI.ts
Normal file
16
view/habiticaAPI.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
// import fetch from "node-fetch";
|
||||||
|
|
||||||
|
|
||||||
|
export async function getTasks(username: string, credentials: string){
|
||||||
|
const url = "https://habitica.com/api/v3/tasks/user?type=todos"
|
||||||
|
const response = fetch(url, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"x-client": username.concat("-testAPI"),
|
||||||
|
"x-api-user": username,
|
||||||
|
"x-api-key": credentials,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return (response)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue