From 98a15c0c9e4b6edf521ccd2ca82c8319fc6e3ef3 Mon Sep 17 00:00:00 2001 From: Leoh Date: Fri, 15 Oct 2021 10:30:25 +0530 Subject: [PATCH] Notices for events and sync errors handled --- ReactView.tsx | 2 +- main.ts | 5 ++++- view.tsx | 2 +- view/App.tsx | 33 +++++++++++++++++++++++++++------ 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/ReactView.tsx b/ReactView.tsx index 9f1a877..e1368a7 100644 --- a/ReactView.tsx +++ b/ReactView.tsx @@ -3,6 +3,6 @@ import App from "./view/App"; export default function ReactView(props: any){ return( - + ) } \ No newline at end of file diff --git a/main.ts b/main.ts index 9d871c8..984a63b 100644 --- a/main.ts +++ b/main.ts @@ -1,4 +1,4 @@ -import { Plugin } from "obsidian"; +import { Notice, Plugin } from "obsidian"; import { ExampleSettingsTab } from "./settings"; import { ExampleView, VIEW_TYPE_EXAMPLE} from "./view" @@ -14,6 +14,9 @@ export default class ExamplePlugin extends Plugin { settings: ExamplePluginSettings; view: ExampleView; + displayNotice(message: string){ + new Notice(message) + } async onload() { await this.loadSettings(); this.addSettingTab(new ExampleSettingsTab(this.app, this)); diff --git a/view.tsx b/view.tsx index 5f69b9b..7bd7c67 100644 --- a/view.tsx +++ b/view.tsx @@ -24,7 +24,7 @@ export class ExampleView extends ItemView { async onOpen() { ReactDOM.render( - , + , this.containerEl.children[1] ) } diff --git a/view/App.tsx b/view/App.tsx index ed6fb2c..e3fec35 100644 --- a/view/App.tsx +++ b/view/App.tsx @@ -26,6 +26,9 @@ class App extends React.Component { } this.handleChange = this.handleChange.bind(this) } + sendNotice(message: string){ + this.props.plugin.displayNotice(message) + } reloadData() { getStats(username, credentials) .then(res => res.json()) @@ -58,9 +61,18 @@ class App extends React.Component { .then(res => res.json()) .then( result => { - console.log("Checked!") - console.log(result) - this.reloadData() + if(result.success) { + this.sendNotice("Checked!") + console.log(result) + this.reloadData() + } else { + this.sendNotice("Resyncing, please try again") + this.reloadData() + } + }, + (error) => { + this.sendNotice("API Error: Please Check crendentials and try again") + console.log(error) } ) } else { @@ -68,9 +80,18 @@ class App extends React.Component { .then(res => res.json()) .then( result => { - console.log("unchecked!") - console.log(result) - this.reloadData() + if(result.success){ + this.sendNotice("unchecked!") + console.log(result) + this.reloadData() + } else { + this.sendNotice("Resyncing, please try again") + this.reloadData() + } + }, + (error) => { + this.sendNotice("API Error: Please Check crendentials and try again") + console.log(error) } ) }