habitica-sync/view.tsx

35 lines
884 B
TypeScript
Raw Permalink Normal View History

2021-10-03 18:10:16 +05:30
import { ItemView,WorkspaceLeaf } from "obsidian";
2021-10-08 10:23:06 +05:30
import * as React from "react";
import * as ReactDOM from "react-dom";
2021-10-10 21:08:13 -07:00
import ReactView from "./ReactView";
import ExamplePlugin from "main";
2021-10-08 10:23:06 +05:30
2021-10-03 18:10:16 +05:30
export const VIEW_TYPE_EXAMPLE = "example-view"
export class ExampleView extends ItemView {
2021-10-10 21:08:13 -07:00
plugin: ExamplePlugin;
2021-10-11 12:40:42 +05:30
constructor(leaf: WorkspaceLeaf, plugin: ExamplePlugin) {
2021-10-03 18:10:16 +05:30
super(leaf)
2021-10-11 12:40:42 +05:30
this.plugin = plugin
}
2021-10-03 18:10:16 +05:30
getViewType() {
return VIEW_TYPE_EXAMPLE
}
getDisplayText() {
return "Example View"
}
async onOpen() {
2021-10-08 10:23:06 +05:30
ReactDOM.render(
<ReactView userID = {this.plugin.settings.userID} tokenAPI = {this.plugin.settings.apiToken} plugin={this.plugin}/>,
2021-10-10 21:08:13 -07:00
this.containerEl.children[1]
2021-10-08 10:23:06 +05:30
)
2021-10-03 18:10:16 +05:30
}
2021-10-08 10:23:06 +05:30
2021-10-03 18:10:16 +05:30
async onClose(){
2021-10-08 10:23:06 +05:30
ReactDOM.unmountComponentAtNode(this.containerEl.children[1]);
2021-10-03 18:10:16 +05:30
}
}