-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
122 lines (101 loc) · 3.06 KB
/
Copy pathApp.jsx
File metadata and controls
122 lines (101 loc) · 3.06 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// 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() {
return {
tasks: Tasks.find({}).fetch()
}
},
renderTasks() {
// Get tasks from this.data.tasks
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();
Tasks.insert({
text: text,
createdAt: new Date(), // current time
owner: Meteor.userId(), // _id of logged in user
username: Meteor.user().username // username of logged in user
});
Meteor.call("addTask", text);
// Clear form
React.findDOMNode(this.refs.textInput).value = "";
},
// Loads items from the Tasks collection and puts them on this.data.tasks
getMeteorData() {
let query = {};
if (this.state.hideCompleted) {
// If hide completed is checked, filter tasks
query = {checked: {$ne: true}};
}
return {
tasks: Tasks.find(query, {sort: {createdAt: -1}}).fetch(),
incompleteCount: Tasks.find({checked: {$ne: true}}).count(),
currentUser: Meteor.user()
};
},
toggleHideCompleted() {
this.setState({
hideCompleted: ! this.state.hideCompleted
});
},
render() {
return (
<div className="container">
<header>
<div><img src="/img/1on1.png"></img></div>
<h1>Interactions List</h1>
Completed: total {this.data.incompleteCount} |
<label className="hide-completed">
to hide <input
type="checkbox"
readOnly={true}
checked={this.state.hideCompleted}
onClick={this.toggleHideCompleted} />
</label>
<label>
| <a href="http://interactions.herokuapp.com/" target="blank">Studio</a>
</label>
<label>
| <span class="box"><a class="button" href="#popup1">How to</a></span>
</label>
<span className="login">
<AccountsUIWrapper />
</span>
<div className="taskheader">
<span className="newtask">
{ this.data.currentUser ?
<form className="new-task" onSubmit={this.handleSubmit} >
<input
type="text"
ref="textInput"
placeholder="Type to add new tasks" />
</form> : ''
}
</span>
<span className="displaydonetasks">
</span>
</div>
</header>
{this.renderTasks()}
</div>
);
}
});