Removed all Example variables, added credential fail handler
This commit is contained in:
parent
cd3c81cf5c
commit
6b715682f9
7 changed files with 82 additions and 89 deletions
42
main.js
42
main.js
File diff suppressed because one or more lines are too long
36
main.ts
36
main.ts
|
|
@ -1,32 +1,40 @@
|
|||
import { Notice, Plugin } from "obsidian";
|
||||
import { ExampleSettingsTab } from "./settings";
|
||||
import { ExampleView, VIEW_TYPE_EXAMPLE} from "./view"
|
||||
import { HabiticaSyncSettingsTab } from "./settings";
|
||||
import { HabiticaSyncView, VIEW_TYPE} from "./view"
|
||||
|
||||
interface ExamplePluginSettings {
|
||||
interface HabiticaSyncSettings {
|
||||
userID: string
|
||||
apiToken: string
|
||||
}
|
||||
const DEFAULT_SETTINGS: Partial<ExamplePluginSettings> = {
|
||||
const DEFAULT_SETTINGS: Partial<HabiticaSyncSettings> = {
|
||||
userID: "",
|
||||
apiToken: ""
|
||||
}
|
||||
export default class ExamplePlugin extends Plugin {
|
||||
settings: ExamplePluginSettings;
|
||||
view: ExampleView;
|
||||
export default class HabiticaSync extends Plugin {
|
||||
settings: HabiticaSyncSettings;
|
||||
view: HabiticaSyncView;
|
||||
|
||||
displayNotice(message: string){
|
||||
new Notice(message)
|
||||
}
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
this.addSettingTab(new ExampleSettingsTab(this.app, this));
|
||||
this.addSettingTab(new HabiticaSyncSettingsTab(this.app, this));
|
||||
this.registerView(
|
||||
VIEW_TYPE_EXAMPLE,
|
||||
(leaf) => (this.view = new ExampleView(leaf, this))
|
||||
VIEW_TYPE,
|
||||
(leaf) => (this.view = new HabiticaSyncView(leaf, this))
|
||||
);
|
||||
this.addRibbonIcon("popup-open", "Open Habitica Pane", () => { //activate view
|
||||
this.activateView();
|
||||
});
|
||||
this.addCommand({
|
||||
id: "habitica-view-open",
|
||||
name: "Habitica: Open Pane",
|
||||
hotkeys: [{ modifiers: ["Mod", "Shift"], key: "h"}],
|
||||
callback: () => {
|
||||
this.activateView();
|
||||
}
|
||||
});
|
||||
}
|
||||
async loadSettings() {
|
||||
this.settings = Object.assign(DEFAULT_SETTINGS, await this.loadData())
|
||||
|
|
@ -38,19 +46,19 @@ export default class ExamplePlugin extends Plugin {
|
|||
await this.view.onClose();
|
||||
|
||||
this.app.workspace
|
||||
.getLeavesOfType(VIEW_TYPE_EXAMPLE)
|
||||
.getLeavesOfType(VIEW_TYPE)
|
||||
.forEach((leaf) => leaf.detach());
|
||||
}
|
||||
async activateView() {
|
||||
this.app.workspace.detachLeavesOfType(VIEW_TYPE_EXAMPLE);
|
||||
this.app.workspace.detachLeavesOfType(VIEW_TYPE);
|
||||
|
||||
await this.app.workspace.getRightLeaf(false).setViewState({
|
||||
type: VIEW_TYPE_EXAMPLE,
|
||||
type: VIEW_TYPE,
|
||||
active: true,
|
||||
});
|
||||
|
||||
this.app.workspace.revealLeaf(
|
||||
this.app.workspace.getLeavesOfType(VIEW_TYPE_EXAMPLE)[0]
|
||||
this.app.workspace.getLeavesOfType(VIEW_TYPE)[0]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "obsidian-habitica-integration",
|
||||
"name": "Obsidian Habitica Integration",
|
||||
"version": "0.0.1",
|
||||
"name": "Habitica Sync",
|
||||
"version": "0.9.1",
|
||||
"minAppVersion": "0.9.12",
|
||||
"description": "This plugin helps integrate Habitica user tasks and stats into Obsidian",
|
||||
"author": "Leoh and Ran",
|
||||
|
|
|
|||
34
old_view.ts
34
old_view.ts
|
|
@ -1,34 +0,0 @@
|
|||
import { ItemView,WorkspaceLeaf } from "obsidian";
|
||||
import * as React from "react";
|
||||
import * as ReactDOM from "react-dom";
|
||||
import ReactView from "./ReactView";
|
||||
import ExamplePlugin from "main";
|
||||
|
||||
|
||||
export const VIEW_TYPE_EXAMPLE = "example-view"
|
||||
|
||||
export class ExampleView extends ItemView {
|
||||
plugin: ExamplePlugin;
|
||||
constructor(leaf: WorkspaceLeaf) {
|
||||
super(leaf)
|
||||
}
|
||||
|
||||
getViewType() {
|
||||
return VIEW_TYPE_EXAMPLE
|
||||
}
|
||||
|
||||
getDisplayText() {
|
||||
return "Example View"
|
||||
}
|
||||
|
||||
async onOpen() {
|
||||
ReactDOM.render(
|
||||
React.createElement(ReactView),
|
||||
this.containerEl.children[1]
|
||||
)
|
||||
}
|
||||
|
||||
async onClose(){
|
||||
ReactDOM.unmountComponentAtNode(this.containerEl.children[1]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
import ExamplePlugin from "main";
|
||||
import HabiticaSync from "main";
|
||||
import { App, PluginSettingTab, Setting } from "obsidian";
|
||||
|
||||
export class ExampleSettingsTab extends PluginSettingTab {
|
||||
plugin: ExamplePlugin;
|
||||
export class HabiticaSyncSettingsTab extends PluginSettingTab {
|
||||
plugin: HabiticaSync;
|
||||
|
||||
constructor(app: App, plugin: ExamplePlugin) {
|
||||
constructor(app: App, plugin: HabiticaSync) {
|
||||
super(app, plugin)
|
||||
this.plugin = plugin
|
||||
}
|
||||
|
|
|
|||
14
view.tsx
14
view.tsx
|
|
@ -2,24 +2,24 @@ import { ItemView,WorkspaceLeaf } from "obsidian";
|
|||
import * as React from "react";
|
||||
import * as ReactDOM from "react-dom";
|
||||
import ReactView from "./ReactView";
|
||||
import ExamplePlugin from "main";
|
||||
import HabiticaSync from "main";
|
||||
|
||||
|
||||
export const VIEW_TYPE_EXAMPLE = "example-view"
|
||||
export const VIEW_TYPE = "example-view"
|
||||
|
||||
export class ExampleView extends ItemView {
|
||||
plugin: ExamplePlugin;
|
||||
constructor(leaf: WorkspaceLeaf, plugin: ExamplePlugin) {
|
||||
export class HabiticaSyncView extends ItemView {
|
||||
plugin: HabiticaSync;
|
||||
constructor(leaf: WorkspaceLeaf, plugin: HabiticaSync) {
|
||||
super(leaf)
|
||||
this.plugin = plugin
|
||||
}
|
||||
|
||||
getViewType() {
|
||||
return VIEW_TYPE_EXAMPLE
|
||||
return VIEW_TYPE
|
||||
}
|
||||
|
||||
getDisplayText() {
|
||||
return "Example View"
|
||||
return "Habitica Pane"
|
||||
}
|
||||
|
||||
async onOpen() {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ class App extends React.Component<any,any> {
|
|||
.then(res => res.json())
|
||||
.then(
|
||||
result => {
|
||||
if(result.success === false){
|
||||
this.sendNotice("Login Failed, Please check credentials and try again!")
|
||||
console.log(result)
|
||||
} else {
|
||||
console.log(result)
|
||||
console.log("data reloaded")
|
||||
this.setState({
|
||||
|
|
@ -41,6 +45,7 @@ class App extends React.Component<any,any> {
|
|||
user_data: result,
|
||||
todos: result.tasks.todos
|
||||
})
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
this.setState({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue