Created task menu, started habits menu

This commit is contained in:
ransurf 2021-10-17 21:58:59 -07:00
parent 9fe8405bab
commit a4ebd7aab3
17 changed files with 623 additions and 37 deletions

View file

@ -3,6 +3,8 @@ import { getStats, scoreTask } from "./habiticaAPI"
import Statsview from "./Components/Statsview"
import Taskview from "./Components/Taskview"
import { domainToASCII } from "url";
let username = ""
let credentials = ""
@ -22,7 +24,9 @@ class App extends React.Component<any,any> {
lvl: 0,
}
},
todos: []
todos: [],
dailys: [],
habits: [],
}
this.handleChange = this.handleChange.bind(this)
}
@ -43,7 +47,10 @@ class App extends React.Component<any,any> {
this.setState({
isLoaded: true,
user_data: result,
todos: result.tasks.todos
tasks: result.tasks,
todos: result.tasks.todos,
dailys: result.tasks.dailys,
habits: result.tasks.habits
})
}
},
@ -102,6 +109,93 @@ class App extends React.Component<any,any> {
}
}
})
this.state.todos.forEach((element: any) => {
if(element.id == event.target.id){
if(!element.completed){
scoreTask(username, credentials, event.target.id, "up")
.then(res => res.json())
.then(
result => {
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 {
scoreTask(username, credentials, event.target.id, "down")
.then(res => res.json())
.then(
result => {
if(result.success){
this.sendNotice("Un-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)
}
)
}
}
})
this.state.dailys.forEach((element: any) => {
if(element.id == event.target.id){
if(!element.completed){
scoreTask(username, credentials, event.target.id, "up")
.then(res => res.json())
.then(
result => {
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 {
scoreTask(username, credentials, event.target.id, "down")
.then(res => res.json())
.then(
result => {
if(result.success){
this.sendNotice("Un-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)
}
)
}
}
})
}
render(){
@ -113,7 +207,7 @@ class App extends React.Component<any,any> {
return (<div className="plugin-root">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<Statsview user_data={this.state.user_data} />
<Taskview todos={this.state.todos} onChange={this.handleChange} />
<Taskview state={this.state.tasks} onChange={this.handleChange} />
</div>
);
}