Notices for events and sync errors handled
This commit is contained in:
parent
a60eade0ae
commit
98a15c0c9e
4 changed files with 33 additions and 9 deletions
|
|
@ -3,6 +3,6 @@ import App from "./view/App";
|
||||||
|
|
||||||
export default function ReactView(props: any){
|
export default function ReactView(props: any){
|
||||||
return(
|
return(
|
||||||
<App username={props.userID} apiToken={props.tokenAPI}/>
|
<App username={props.userID} apiToken={props.tokenAPI} plugin={props.plugin}/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
5
main.ts
5
main.ts
|
|
@ -1,4 +1,4 @@
|
||||||
import { Plugin } from "obsidian";
|
import { Notice, Plugin } from "obsidian";
|
||||||
import { ExampleSettingsTab } from "./settings";
|
import { ExampleSettingsTab } from "./settings";
|
||||||
import { ExampleView, VIEW_TYPE_EXAMPLE} from "./view"
|
import { ExampleView, VIEW_TYPE_EXAMPLE} from "./view"
|
||||||
|
|
||||||
|
|
@ -14,6 +14,9 @@ export default class ExamplePlugin extends Plugin {
|
||||||
settings: ExamplePluginSettings;
|
settings: ExamplePluginSettings;
|
||||||
view: ExampleView;
|
view: ExampleView;
|
||||||
|
|
||||||
|
displayNotice(message: string){
|
||||||
|
new Notice(message)
|
||||||
|
}
|
||||||
async onload() {
|
async onload() {
|
||||||
await this.loadSettings();
|
await this.loadSettings();
|
||||||
this.addSettingTab(new ExampleSettingsTab(this.app, this));
|
this.addSettingTab(new ExampleSettingsTab(this.app, this));
|
||||||
|
|
|
||||||
2
view.tsx
2
view.tsx
|
|
@ -24,7 +24,7 @@ export class ExampleView extends ItemView {
|
||||||
|
|
||||||
async onOpen() {
|
async onOpen() {
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<ReactView userID = {this.plugin.settings.userID} tokenAPI = {this.plugin.settings.apiToken}/>,
|
<ReactView userID = {this.plugin.settings.userID} tokenAPI = {this.plugin.settings.apiToken} plugin={this.plugin}/>,
|
||||||
this.containerEl.children[1]
|
this.containerEl.children[1]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
33
view/App.tsx
33
view/App.tsx
|
|
@ -26,6 +26,9 @@ class App extends React.Component<any,any> {
|
||||||
}
|
}
|
||||||
this.handleChange = this.handleChange.bind(this)
|
this.handleChange = this.handleChange.bind(this)
|
||||||
}
|
}
|
||||||
|
sendNotice(message: string){
|
||||||
|
this.props.plugin.displayNotice(message)
|
||||||
|
}
|
||||||
reloadData() {
|
reloadData() {
|
||||||
getStats(username, credentials)
|
getStats(username, credentials)
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
|
|
@ -58,9 +61,18 @@ class App extends React.Component<any,any> {
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(
|
.then(
|
||||||
result => {
|
result => {
|
||||||
console.log("Checked!")
|
if(result.success) {
|
||||||
console.log(result)
|
this.sendNotice("Checked!")
|
||||||
this.reloadData()
|
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 {
|
} else {
|
||||||
|
|
@ -68,9 +80,18 @@ class App extends React.Component<any,any> {
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(
|
.then(
|
||||||
result => {
|
result => {
|
||||||
console.log("unchecked!")
|
if(result.success){
|
||||||
console.log(result)
|
this.sendNotice("unchecked!")
|
||||||
this.reloadData()
|
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)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue