-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.jsx
76 lines (68 loc) · 2.26 KB
/
task.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
// Task React component - represents a single todo item
Task = React.createClass ({
propTypes: {
/**
* This component gets the task to display through a React prop
* We can use propTypes to indicate it is required
*/
task: React.PropTypes.object.isRequired,
showPrivateButton: React.PropTypes.bool.isRequired,
showDeleteButton: React.PropTypes.bool.isRequired
},
toggleChecked() {
/**
* Calls setChecked method
* Sets the checked property to the opposite of its current value
*/
Meteor.call('setChecked', this.props.task._id, ! this.props.task.checked);
},
deleteThisTask() {
// Calls removeTask method
Meteor.call('removeTask', this.props.task._id);
},
togglePrivate() {
// Calls setPrivate method
Meteor.call('setPrivate', this.props.task._id, ! this.props.task.private);
},
// Renders a single todo item
render() {
/**
* Gives tasks a different className when they are checked off,
* so that we can style them nicely in CSS
* Adds "checked and/or private to the className when needed
*/
const taskClassName = (this.props.task.checked ? 'checked' : '') + ' ' +
(this.props.task.private ? 'private' : '');
return (
/**
* Returns a li with the class checked only if the task is checked.
* Has a delete button which deletes a task, only owner can delete his
* tasks
* Has a checkbox to check a task as completed or to uncheck
* The username of task's owner
* Task's text and private/public option
*/
<li className={taskClassName}>
{ this.props.showDeleteButton ? (
<button className='delete' onClick={this.deleteThisTask}>
×
</button>
) : ''}
<input
type='checkbox'
readOnly={true}
checked={this.props.task.checked}
onClick={this.toggleChecked}
/>
{ this.props.showPrivateButton ? (
<button className='toggle-private' onClick={this.togglePrivate}>
{ this.props.task.private ? 'Private' : 'Public' }
</button>
) : ''}
<span className='text'>
<strong>{this.props.task.username}</strong>: {this.props.task.text}
</span>
</li>
);
}
});