-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (49 loc) · 1.33 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import registerServiceWorker from './registerServiceWorker';
import InputTask from "./inputTask.js";
import TaskList from "./taskList.js";
class App extends Component{
constructor(props){
super(props);
this.state = {
tasks: {}
};
this.addTask = this.addTask.bind(this);
this.removeTask = this.removeTask.bind(this);
this.updateTaskStatus = this.updateTaskStatus.bind(this);
}
addTask(task){
const tasks = {...this.state.tasks}; //take a copy
const timestamp = task.time;
tasks[`task-${timestamp}`] = task;
this.setState({tasks});
}
removeTask(task){
const tasks = {...this.state.tasks}; //take a copy
delete tasks[`${task}`]
this.setState({tasks});
}
updateTaskStatus(task){
const tasks = {...this.state.tasks};
if ( tasks[`${task}`].status === "Incomplete"){
tasks[`${task}`].status = "Complete";
} else{
tasks[`${task}`].status = "Incomplete";
}
this.setState({tasks});
}
render(){
console.log("Inside App render method");
return(
<div>
<InputTask addTask={this.addTask}/>
<TaskList updateTaskStatus= {this.updateTaskStatus} removeTask={this.removeTask} tasks={this.state.tasks}/>
</div>
)
}
}
ReactDOM.render(<App/>,
document.getElementById("root")
);