-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.jsx
78 lines (74 loc) · 2.13 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// App component - represents the whole app
App = React.createClass({
// This mixin makes the getMeteorData method work
mixins: [ReactMeteorData],
getInitialState() {
return {
hideCompleted: false
}
},
// Loads items from the Tasks collection and puts them on this.data.tasks
getMeteorData() {
let query ={};
if(this.state.hideCompleted){
query ={checked: {$ne: true}};
}
return {
tasks: Tasks.find(query, {sort: {createdAt: -1}}).fetch(),
incompleteCount: Tasks.find({checked: {$ne: true}}).count(),
currentUser: Meteor.user()
};
},
renderTasks() {
return this.data.tasks.map((task) => {
const currentUserId = this.data.currentUser && this.data.currentUser._id;
const showPrivateButton = task.owner === currentUserId;
return <Task
key={task._id}
task={task}
showPrivateButton={showPrivateButton} />;
});
},
handleSubmit(event) {
event.preventDefault();
// Find the text field via the React ref
var text = React.findDOMNode(this.refs.textInput).value.trim();
Meteor.call("addTask", text);
// Clear form
React.findDOMNode(this.refs.textInput).value = "";
},
toggleHideCompleted() {
this.setState({
hideCompleted: ! this.state.hideCompleted
});
},
render() {
return (
<div className="container">
<header>
<h1>Todo List({this.data.incompleteCount})</h1>
<label className="hide-completed">
<input
type="checkbox"
readOnly={true}
checked={this.state.hideCompleted}
onClick={this.toggleHideCompleted} />
Hide Completed Tasks
</label>
<AccountsUIWrapper />
{ this.data.currentUser ?
<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>
);
}
});