Skip to content

Commit 61571c1

Browse files
extracted code into TodoForm
1 parent d835723 commit 61571c1

File tree

2 files changed

+50
-31
lines changed

2 files changed

+50
-31
lines changed
Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import TodoForm from './TodoForm';
23
import DisplayList from './DisplayList';
34

45
var rand = require('random-key');
@@ -35,43 +36,22 @@ export default class App extends React.Component {
3536
})
3637
}
3738

38-
handleSubmit (event) {
39-
event.preventDefault();
40-
41-
var newTodo = { title: this.state.title, done: false };
42-
43-
TodoActions.addTodo(newTodo);
44-
this.setState({ title: '' });
45-
}
46-
47-
handleChange (event) {
48-
var title = event.target.value;
49-
this.setState({ title: title });
50-
}
51-
5239
handleClearCompleted (event) {
5340
var newTodos = this.state.todos.filter((todo) => { return !todo.done});
5441
this.setState({ todos: newTodos });
5542
}
5643

5744
render () {
58-
return <div>
59-
<h1> TODO </h1>
60-
<form onSubmit={this.handleSubmit.bind(this)}>
61-
<input type="text"
62-
onChange={this.handleChange.bind(this)}
63-
value={this.state.title} />
64-
</form>
65-
66-
<DisplayList
45+
return <div>
46+
<TodoForm />
47+
<DisplayList
6748
todos={this.state.todos} />
68-
69-
<footer>
70-
All: ({ this.state.todos.length }) |
71-
Completed: ({ this.state.todos.filter((todo) => { return todo.done }).length }) |
72-
Pending: ({ this.state.todos.filter((todo) => { return !todo.done }).length }) |
73-
<a href='#' onClick={this.handleClearCompleted.bind(this)}>Clear Completed</a>
74-
</footer>
75-
</div>;
49+
<footer>
50+
All: ({ this.state.todos.length }) |
51+
Completed: ({ this.state.todos.filter((todo) => { return todo.done }).length }) |
52+
Pending: ({ this.state.todos.filter((todo) => { return !todo.done }).length }) |
53+
<a href='#' onClick={this.handleClearCompleted.bind(this)}>Clear Completed</a>
54+
</footer>
55+
</div>
7656
}
7757
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react';
2+
import DisplayList from './DisplayList';
3+
import DisplayItem from './DisplayItem';
4+
5+
var TodoActions = require('../actions/TodoActions');
6+
7+
export default class TodoForm extends React.Component {
8+
9+
constructor () {
10+
super();
11+
this.state = { editing: false }
12+
}
13+
14+
handleSubmit (event) {
15+
event.preventDefault();
16+
17+
var newTodo = { title: this.state.title, done: false };
18+
19+
TodoActions.addTodo(newTodo);
20+
this.setState({ title: '' });
21+
}
22+
23+
handleChange (event) {
24+
var title = event.target.value;
25+
this.setState({ title: title });
26+
}
27+
28+
render () {
29+
return <div>
30+
<h1> TODO </h1>
31+
<form onSubmit={this.handleSubmit.bind(this)}>
32+
<input type="text"
33+
onChange={this.handleChange.bind(this)}
34+
value={this.state.title} />
35+
</form>
36+
</div>;
37+
}
38+
39+
}

0 commit comments

Comments
 (0)