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 { Notice, Plugin } from "obsidian";
|
||||||
import { ExampleSettingsTab } from "./settings";
|
import { HabiticaSyncSettingsTab } from "./settings";
|
||||||
import { ExampleView, VIEW_TYPE_EXAMPLE} from "./view"
|
import { HabiticaSyncView, VIEW_TYPE} from "./view"
|
||||||
|
|
||||||
interface ExamplePluginSettings {
|
interface HabiticaSyncSettings {
|
||||||
userID: string
|
userID: string
|
||||||
apiToken: string
|
apiToken: string
|
||||||
}
|
}
|
||||||
const DEFAULT_SETTINGS: Partial<ExamplePluginSettings> = {
|
const DEFAULT_SETTINGS: Partial<HabiticaSyncSettings> = {
|
||||||
userID: "",
|
userID: "",
|
||||||
apiToken: ""
|
apiToken: ""
|
||||||
}
|
}
|
||||||
export default class ExamplePlugin extends Plugin {
|
export default class HabiticaSync extends Plugin {
|
||||||
settings: ExamplePluginSettings;
|
settings: HabiticaSyncSettings;
|
||||||
view: ExampleView;
|
view: HabiticaSyncView;
|
||||||
|
|
||||||
displayNotice(message: string){
|
displayNotice(message: string){
|
||||||
new Notice(message)
|
new Notice(message)
|
||||||
}
|
}
|
||||||
async onload() {
|
async onload() {
|
||||||
await this.loadSettings();
|
await this.loadSettings();
|
||||||
this.addSettingTab(new ExampleSettingsTab(this.app, this));
|
this.addSettingTab(new HabiticaSyncSettingsTab(this.app, this));
|
||||||
this.registerView(
|
this.registerView(
|
||||||
VIEW_TYPE_EXAMPLE,
|
VIEW_TYPE,
|
||||||
(leaf) => (this.view = new ExampleView(leaf, this))
|
(leaf) => (this.view = new HabiticaSyncView(leaf, this))
|
||||||
);
|
);
|
||||||
this.addRibbonIcon("popup-open", "Open Habitica Pane", () => { //activate view
|
this.addRibbonIcon("popup-open", "Open Habitica Pane", () => { //activate view
|
||||||
this.activateView();
|
this.activateView();
|
||||||
});
|
});
|
||||||
|
this.addCommand({
|
||||||
|
id: "habitica-view-open",
|
||||||
|
name: "Habitica: Open Pane",
|
||||||
|
hotkeys: [{ modifiers: ["Mod", "Shift"], key: "h"}],
|
||||||
|
callback: () => {
|
||||||
|
this.activateView();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
async loadSettings() {
|
async loadSettings() {
|
||||||
this.settings = Object.assign(DEFAULT_SETTINGS, await this.loadData())
|
this.settings = Object.assign(DEFAULT_SETTINGS, await this.loadData())
|
||||||
|
|
@ -38,19 +46,19 @@ export default class ExamplePlugin extends Plugin {
|
||||||
await this.view.onClose();
|
await this.view.onClose();
|
||||||
|
|
||||||
this.app.workspace
|
this.app.workspace
|
||||||
.getLeavesOfType(VIEW_TYPE_EXAMPLE)
|
.getLeavesOfType(VIEW_TYPE)
|
||||||
.forEach((leaf) => leaf.detach());
|
.forEach((leaf) => leaf.detach());
|
||||||
}
|
}
|
||||||
async activateView() {
|
async activateView() {
|
||||||
this.app.workspace.detachLeavesOfType(VIEW_TYPE_EXAMPLE);
|
this.app.workspace.detachLeavesOfType(VIEW_TYPE);
|
||||||
|
|
||||||
await this.app.workspace.getRightLeaf(false).setViewState({
|
await this.app.workspace.getRightLeaf(false).setViewState({
|
||||||
type: VIEW_TYPE_EXAMPLE,
|
type: VIEW_TYPE,
|
||||||
active: true,
|
active: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.app.workspace.revealLeaf(
|
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",
|
"id": "obsidian-habitica-integration",
|
||||||
"name": "Obsidian Habitica Integration",
|
"name": "Habitica Sync",
|
||||||
"version": "0.0.1",
|
"version": "0.9.1",
|
||||||
"minAppVersion": "0.9.12",
|
"minAppVersion": "0.9.12",
|
||||||
"description": "This plugin helps integrate Habitica user tasks and stats into Obsidian",
|
"description": "This plugin helps integrate Habitica user tasks and stats into Obsidian",
|
||||||
"author": "Leoh and Ran",
|
"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";
|
import { App, PluginSettingTab, Setting } from "obsidian";
|
||||||
|
|
||||||
export class ExampleSettingsTab extends PluginSettingTab {
|
export class HabiticaSyncSettingsTab extends PluginSettingTab {
|
||||||
plugin: ExamplePlugin;
|
plugin: HabiticaSync;
|
||||||
|
|
||||||
constructor(app: App, plugin: ExamplePlugin) {
|
constructor(app: App, plugin: HabiticaSync) {
|
||||||
super(app, plugin)
|
super(app, plugin)
|
||||||
this.plugin = 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 React from "react";
|
||||||
import * as ReactDOM from "react-dom";
|
import * as ReactDOM from "react-dom";
|
||||||
import ReactView from "./ReactView";
|
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 {
|
export class HabiticaSyncView extends ItemView {
|
||||||
plugin: ExamplePlugin;
|
plugin: HabiticaSync;
|
||||||
constructor(leaf: WorkspaceLeaf, plugin: ExamplePlugin) {
|
constructor(leaf: WorkspaceLeaf, plugin: HabiticaSync) {
|
||||||
super(leaf)
|
super(leaf)
|
||||||
this.plugin = plugin
|
this.plugin = plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
getViewType() {
|
getViewType() {
|
||||||
return VIEW_TYPE_EXAMPLE
|
return VIEW_TYPE
|
||||||
}
|
}
|
||||||
|
|
||||||
getDisplayText() {
|
getDisplayText() {
|
||||||
return "Example View"
|
return "Habitica Pane"
|
||||||
}
|
}
|
||||||
|
|
||||||
async onOpen() {
|
async onOpen() {
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,10 @@ class App extends React.Component<any,any> {
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(
|
.then(
|
||||||
result => {
|
result => {
|
||||||
|
if(result.success === false){
|
||||||
|
this.sendNotice("Login Failed, Please check credentials and try again!")
|
||||||
|
console.log(result)
|
||||||
|
} else {
|
||||||
console.log(result)
|
console.log(result)
|
||||||
console.log("data reloaded")
|
console.log("data reloaded")
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|
@ -41,6 +45,7 @@ class App extends React.Component<any,any> {
|
||||||
user_data: result,
|
user_data: result,
|
||||||
todos: result.tasks.todos
|
todos: result.tasks.todos
|
||||||
})
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue