-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.jsx
63 lines (52 loc) · 1.18 KB
/
App.jsx
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
// App component - represents the whole app
App = React.createClass({
getTasks() {
return [
{ _id: 1, text: "This is task 1" },
{ _id: 2, text: "This is task 2" },
{ _id: 3, text: "This is task 3" }
];
},
// This mixin makes the getMeteorData method work
mixins: [ReactMeteorData],
getMeteorData(){
return{
tasks: Tasks.find({}, {sort: {createdAt: -1}}).fetch()
}
},
renderTasks(){
// Get tasks from this.data.tasks
return this.data.tasks.map((task) => {
return <Task key={task._id} task={task} />;
});
},
handleSubmit(event) {
event.preventDefault();
// Find the text field via the React ref
var text = React.findDOMNode(this.refs.textInput).value.trim();
Tasks.insert({
text: text,
createdAt: new Date() // current time
});
// Clear form
React.findDOMNode(this.refs.textInput).value = "";
},
render(){
return (
<div className="container">
<header>
<h1>Todo List</h1>
<form className="new-task" onSubmit={this.handleSubmit} >
<input
type="text"
ref="textInput"
placeholder="Type to add new tasks" />
</form>
</header>
<ul>
{this.renderTasks()}
</ul>
</div>
);
}
});