-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
64 lines (56 loc) · 1.61 KB
/
app.js
File metadata and controls
64 lines (56 loc) · 1.61 KB
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 from 'react';
import CreateTodo from './create-todo.js';
import TodosList from './todos-list.js';
const todos = [
{
task: 'make React tutorial',
isCompleted: false
},
{
task: 'eat dinner',
isCompleted: true
}
];
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
todos
};
}
render() {
return (
<div>
<h1>React ToDos App</h1>
<CreateTodo todos={this.state.todos} createTask={this.createTask.bind(this)} />
<TodosList
todos={this.state.todos}
toggleTask={this.toggleTask.bind(this)}
saveTask={this.saveTask.bind(this)}
deleteTask={this.deleteTask.bind(this)}
/>
</div>
);
}
toggleTask(task) {
const foundTodo = find(this.state.todos, todo => todo.task === task);
foundTodo.isCompleted = !foundTodo.isCompleted;
this.setState({ todos: this.state.todos });
}
createTask(task) {
this.state.todos.push({
task,
isCompleted: false
});
this.setState({ todos: this.state.todos });
}
saveTask(oldTask, newTask) {
const foundTodo = find(this.state.todos, todo => todo.task === oldTask);
foundTodo.task = newTask;
this.setState({ todos: this.state.todos });
}
deleteTask(taskToDelete) {
delete(this.state.todos, todo => todo.task === taskToDelete);
this.setState({ todos: this.state.todos });
}
}