Encapsulated user information into App class
This commit is contained in:
parent
86f4fd0d74
commit
faa33a5655
1 changed files with 8 additions and 7 deletions
|
|
@ -4,14 +4,15 @@ import { getStats, scoreTask } from "./habiticaAPI"
|
||||||
import Statsview from "./Components/Statsview"
|
import Statsview from "./Components/Statsview"
|
||||||
import Taskview from "./Components/Taskview"
|
import Taskview from "./Components/Taskview"
|
||||||
|
|
||||||
let username = ""
|
|
||||||
let credentials = ""
|
|
||||||
|
|
||||||
class App extends React.Component<any,any> {
|
class App extends React.Component<any,any> {
|
||||||
|
username = ""
|
||||||
|
credentials = ""
|
||||||
constructor(props: any) {
|
constructor(props: any) {
|
||||||
super(props)
|
super(props)
|
||||||
username = this.props.plugin.settings.userID
|
this.username = this.props.plugin.settings.userID
|
||||||
credentials = this.props.plugin.settings.apiToken
|
this.credentials = this.props.plugin.settings.apiToken
|
||||||
this.state = {
|
this.state = {
|
||||||
isLoaded: false,
|
isLoaded: false,
|
||||||
user_data: {
|
user_data: {
|
||||||
|
|
@ -37,11 +38,11 @@ class App extends React.Component<any,any> {
|
||||||
new Notice(message)
|
new Notice(message)
|
||||||
}
|
}
|
||||||
async reloadData() {
|
async reloadData() {
|
||||||
const result = (await getStats(username, credentials)).json()
|
const result = (await getStats(this.username, this.credentials)).json()
|
||||||
result.then(
|
result.then(
|
||||||
result => {
|
result => {
|
||||||
if(result.success === false){
|
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 {
|
} else {
|
||||||
this.setState({
|
this.setState({
|
||||||
isLoaded: true,
|
isLoaded: true,
|
||||||
|
|
@ -63,7 +64,7 @@ class App extends React.Component<any,any> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendScore(id:string , score: string, message: string){
|
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.then(
|
||||||
result => {
|
result => {
|
||||||
if(result.success) {
|
if(result.success) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue