-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
94 lines (92 loc) · 3.13 KB
/
test.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
class ClickButton extends React.Component {
constructor(props) {
super(props);
this.state = {all: []};
};
addTask = () => {
this.setState(prevState => {
return {all: [...prevState.all, {value: this.refs.task.value, done: false, checked: false, hide: false}]}
});
};
deleteTask = index => {
this.setState(prevState =>{
prevState.all.splice(index, 1);
return {all: prevState.all}
});
};
checked = index => {
this.setState(prevState => {
prevState.all[index].checked = !prevState.all[index].checked;
prevState.all[index].done = !prevState.all[index].done;
return {all: prevState.all};
});
console.log(this.state.all)
};
createTasks = () =>{
return Array.from(new Array(this.state.all.length), (cur, i) => {
let className = this.state.all[i].done ? 'cross' : 'notCross';
if(this.state.all[i].hide) return;
return <tr>
<td>
<input id={i} onChange={() => this.checked(i)} className={'check'} type={'checkbox'}/>
<h5 className={className}>{this.state.all[i].value}</h5>
</td>
<td><button className={'buttonDelete'} onClick={() => this.deleteTask(i)}/></td>
</tr>
});
};
allTasks = () => {
this.setState(prevState => {
prevState.all.forEach(cur => {
cur.hide = false;
});
return prevState.all;
})
};
doneTasks = () => {
this.setState(prevState => {
prevState.all.forEach(cur => {
cur.hide = !cur.done;
});
return {all: prevState.all}
})
};
notDoneTasks = () => {
this.setState(prevState => {
prevState.all.forEach(cur => {
cur.hide = !!cur.done;
});
return {all: prevState.all}
})
};
render() {
return <div>
<table>
<tr className={'addTask'}>
<td>
<input ref='task'
className={"inputText"}
type={"text"}
placeholder={"Напиши что-то"} />
</td>
<td>
<button className={'buttonAdd'} onClick={this.addTask}>Добавить</button>
</td>
</tr>
{this.createTasks()}
</table>
<table className={'info'}>
<tr>
<td>Количество: {this.state.all.length}</td>
<td><input onChange={this.allTasks} type={'radio'}/>Все</td>
<td><input onChange={this.doneTasks} type={'radio'}/>Сделаные</td>
<td><input onChange={this.notDoneTasks} type={'radio'}/>Не сделаные</td>
</tr>
</table>
</div>
};
}
ReactDOM.render(
<ClickButton />,
document.getElementById('root')
);