From faa33a5655450221ee18bd73dfacee09bf75abe0 Mon Sep 17 00:00:00 2001 From: ransurf Date: Thu, 28 Oct 2021 21:53:15 -0700 Subject: [PATCH 1/2] Encapsulated user information into App class --- src/view/App.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/view/App.tsx b/src/view/App.tsx index fd8bdff..5243df5 100644 --- a/src/view/App.tsx +++ b/src/view/App.tsx @@ -4,14 +4,15 @@ import { getStats, scoreTask } from "./habiticaAPI" import Statsview from "./Components/Statsview" import Taskview from "./Components/Taskview" -let username = "" -let credentials = "" + class App extends React.Component { + username = "" + credentials = "" constructor(props: any) { super(props) - username = this.props.plugin.settings.userID - credentials = this.props.plugin.settings.apiToken + this.username = this.props.plugin.settings.userID + this.credentials = this.props.plugin.settings.apiToken this.state = { isLoaded: false, user_data: { @@ -37,11 +38,11 @@ class App extends React.Component { new Notice(message) } async reloadData() { - const result = (await getStats(username, credentials)).json() + const result = (await getStats(this.username, this.credentials)).json() result.then( result => { if(result.success === false){ - this.sendNotice("Login Failed, Please check credentials and try again!") + this.sendNotice("Login Failed, Please check this.credentials and try again!") } else { this.setState({ isLoaded: true, @@ -63,7 +64,7 @@ class App extends React.Component { } async sendScore(id:string , score: string, message: string){ - const result = (await scoreTask(username, credentials, id, score)).json() + const result = (await scoreTask(this.username, this.credentials, id, score)).json() result.then( result => { if(result.success) { From e8b010a3c5aeb3e735be31c4f8b5f58e98ab981b Mon Sep 17 00:00:00 2001 From: Zain Date: Sat, 30 Oct 2021 10:04:59 +0530 Subject: [PATCH 2/2] Changed sync syntax and removed uncessary function --- manifest.json | 2 +- src/view/App.tsx | 70 +++++++++++++++++++++--------------------------- 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/manifest.json b/manifest.json index bfa0b32..b537c6e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-habitica-integration", "name": "Habitica Sync", - "version": "0.9.6", + "version": "0.9.7", "minAppVersion": "0.9.12", "description": "This plugin helps integrate Habitica user tasks and stats into Obsidian", "author": "Leoh and Ran", diff --git a/src/view/App.tsx b/src/view/App.tsx index 5243df5..3b1882d 100644 --- a/src/view/App.tsx +++ b/src/view/App.tsx @@ -4,8 +4,6 @@ import { getStats, scoreTask } from "./habiticaAPI" import Statsview from "./Components/Statsview" import Taskview from "./Components/Taskview" - - class App extends React.Component { username = "" credentials = "" @@ -33,53 +31,45 @@ class App extends React.Component { this.handleChangeHabits = this.handleChangeHabits.bind(this) - } - sendNotice(message: string){ - new Notice(message) } async reloadData() { - const result = (await getStats(this.username, this.credentials)).json() - result.then( - result => { - if(result.success === false){ - this.sendNotice("Login Failed, Please check this.credentials and try again!") - } else { - this.setState({ - isLoaded: true, - user_data: result, - tasks: result.tasks, - }) - } - }, - (error) => { - this.setState({ - isLoaded: true, - error - }) - } - ) + try { + let response = await getStats(this.username, this.credentials); + let result = await response.json(); + if (result.success === false) { + new Notice('Login Failed, Please check credentials and try again!'); + } + else { + this.setState({ + isLoaded: true, + user_data: result, + tasks: result.tasks, + }); + } + } catch (e) { + console.log(e); + new Notice("API Error: Please check credentials") + } } componentDidMount() { this.reloadData() } async sendScore(id:string , score: string, message: string){ - const result = (await scoreTask(this.username, this.credentials, id, score)).json() - result.then( - result => { - if(result.success) { - this.sendNotice(message) - 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) + try { + let response = await scoreTask(this.username, this.credentials, id, score); + let result = await response.json(); + if(result.success === true){ + new Notice(message); + this.reloadData(); + } else { + new Notice("Resyncing, please try again"); + this.reloadData(); } - ) + } catch (e) { + console.log(e); + new Notice("API Error: Please check credentials") + } } handleChangeTodos(event: any){