Skip to content

Commit

Permalink
Step 5 of TODO App with React tutorial - adding UI for checking off a…
Browse files Browse the repository at this point in the history
…nd deleting TODO items
  • Loading branch information
itamaro committed Nov 28, 2015
1 parent 898c290 commit ac69d1b
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion Task.jsx
Expand Up @@ -5,9 +5,37 @@ Task = React.createClass({
// We can use propTypes to indicate it is required // We can use propTypes to indicate it is required
task: React.PropTypes.object.isRequired task: React.PropTypes.object.isRequired
}, },

toggleChecked() {
// Set the checked property to the opposite of its current value
Tasks.update(this.props.task._id, {
$set: {checked: ! this.props.task.checked}
});
},

deleteThisTask() {
Tasks.remove(this.props.task._id);
},

render() { render() {
// Give tasks a different className when they are checked off,
// so that we can style them nicely in CSS
const taskClassName = this.props.task.checked ? "checked" : "";

return ( return (
<li>{this.props.task.text}</li> <li className={taskClassName}>
<button className="delete" onClick={this.deleteThisTask}>
&times;
</button>

<input
type="checkbox"
readOnly={true}
checked={this.props.task.checked}
onClick={this.toggleChecked} />

<span className="text">{this.props.task.text}</span>
</li>
); );
} }
}); });

0 comments on commit ac69d1b

Please sign in to comment.