-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo-list-clean.patch
90 lines (83 loc) · 2.83 KB
/
todo-list-clean.patch
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
diff --git a/todo-list/src/components/Item.jsx b/todo-list/src/components/Item.jsx
index 1740c2a..10da93d 100644
--- a/todo-list/src/components/Item.jsx
+++ b/todo-list/src/components/Item.jsx
@@ -14,10 +14,7 @@ export default class Item extends React.Component {
render() {
return (
<li>
- <span>
- <span>{this.props.message}</span>
- <a href="#" onClick={this.onDelete}>DEL</a>
- </span>
+ {/* span span del */}
</li>
);
}
diff --git a/todo-list/src/components/List.jsx b/todo-list/src/components/List.jsx
index 6a7341b..782491c 100644
--- a/todo-list/src/components/List.jsx
+++ b/todo-list/src/components/List.jsx
@@ -9,7 +9,7 @@ export default class ConfigurationForm extends React.Component {
this.state = {
messageBeingWritten: "",
- items: this.loadItems()
+ items: [] /* loadItems */
};
// https://reactjs.org/docs/handling-events.html
@@ -18,46 +18,20 @@ export default class ConfigurationForm extends React.Component {
this.onDelete = this.onDelete.bind(this);
}
- loadItems() {
- const items = window.localStorage.getItem("todo-items");
- return items ? JSON.parse(items) : [];
- }
-
- saveItems(items) {
- window.localStorage.setItem("todo-items", JSON.stringify(items))
- }
+ /* loadItems */
+ /* saveItems */
onSubmit(e) {
e.preventDefault();
- this.setState(state => {
- if (state.messageBeingWritten) {
- return {
- messageBeingWritten: "",
- items: [...state.items, { id: uuid.v4(), message: state.messageBeingWritten }]
- };
- }
- }, () => {
- this.saveItems(this.state.items)
- });
+ /* setState */
}
onChange(e) {
- this.setState({
- messageBeingWritten: e.target.value
- });
+ /* setState */
}
onDelete(id) {
- this.setState(state => {
- const i = state.items.findIndex(item => item.id == id);
- if (i !== -1) {
- const items = [...state.items];
- items.splice(i, 1);
- return { items }
- }
- }, () => {
- this.saveItems(this.state.items)
- });
+ /* setState */
}
render() {
@@ -73,7 +47,7 @@ export default class ConfigurationForm extends React.Component {
<button type="submit">Add</button>
</form>
<ul>
- {this.state.items.map(item => <Item key={item.id} id={item.id} message={item.message} onDelete={this.onDelete} />)}
+ {/* items map */}
</ul>
</div>
);