Multiple Changes

This commit is contained in:
Leoh 2021-10-19 10:54:06 +05:30
parent a4ebd7aab3
commit 30dd6590ec
19 changed files with 330 additions and 278 deletions

View file

@ -28,7 +28,11 @@ class App extends React.Component<any,any> {
dailys: [],
habits: [],
}
this.handleChange = this.handleChange.bind(this)
this.handleChangeTodos = this.handleChangeTodos.bind(this)
this.handleChangeDailys = this.handleChangeDailys.bind(this)
this.handleChangeHabits = this.handleChangeHabits.bind(this)
}
sendNotice(message: string){
this.props.plugin.displayNotice(message)
@ -48,9 +52,6 @@ class App extends React.Component<any,any> {
isLoaded: true,
user_data: result,
tasks: result.tasks,
todos: result.tasks.todos,
dailys: result.tasks.dailys,
habits: result.tasks.habits
})
}
},
@ -65,8 +66,8 @@ class App extends React.Component<any,any> {
componentDidMount() {
this.reloadData()
}
handleChange(event: any){
this.state.todos.forEach((element: any) => {
handleChangeTodos(event: any){
this.state.tasks.todos.forEach((element: any) => {
if(element.id == event.target.id){
if(!element.completed){
scoreTask(username, credentials, event.target.id, "up")
@ -109,7 +110,9 @@ class App extends React.Component<any,any> {
}
}
})
this.state.todos.forEach((element: any) => {
}
handleChangeDailys(event: any){
this.state.tasks.dailys.forEach((element: any) => {
if(element.id == event.target.id){
if(!element.completed){
scoreTask(username, credentials, event.target.id, "up")
@ -152,34 +155,19 @@ class App extends React.Component<any,any> {
}
}
})
this.state.dailys.forEach((element: any) => {
if(element.id == event.target.id){
if(!element.completed){
scoreTask(username, credentials, event.target.id, "up")
}
handleChangeHabits(event: any){
const target_id = event.target.id.slice(4)
console.log(target_id)
if(event.target.id.slice(0,4) == "plus"){
this.state.tasks.habits.forEach((element: any) => {
if(element.id == target_id){
scoreTask(username, credentials, 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!")
this.sendNotice("Plus!")
console.log(result)
this.reloadData()
} else {
@ -193,9 +181,32 @@ class App extends React.Component<any,any> {
}
)
}
}
})
})
}
else {
this.state.tasks.habits.forEach((element: any) => {
if(element.id == target_id){
scoreTask(username, credentials, target_id, "down")
.then(res => res.json())
.then(
result => {
if(result.success) {
this.sendNotice("Minus :(")
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(){
@ -207,7 +218,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 state={this.state.tasks} onChange={this.handleChange} />
<Taskview data={this.state.tasks} handleChangeTodos={this.handleChangeTodos} handleChangeDailys={this.handleChangeDailys} handleChangeHabits={this.handleChangeHabits}/>
</div>
);
}