Task.jsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Task component: represents a single todo item.
  2. Task = React.createClass({
  3. propTypes: {
  4. // We can use propTypes to indicate it is required.
  5. task: React.PropTypes.object.isRequired,
  6. showPrivateButton: React.PropTypes.bool.isRequired
  7. },
  8. toggleChecked() {
  9. // Set the checked property to the opposite of its current value.
  10. Meteor.call("setChecked", this.props.task._id, ! this.props.task.checked);
  11. },
  12. deleteThisTask() {
  13. Meteor.call("removeTask", this.props.task._id);
  14. },
  15. togglePrivate() {
  16. Meteor._debug('Toggling private on task', this.props.task._id);
  17. Meteor.call("setPrivate", this.props.task._id, ! this.props.task.private);
  18. },
  19. render() {
  20. // Give tasks a different clasSName when they are checked off,
  21. // so that we can style them nicely in CSS.
  22. const taskClassName = (this.props.task.checked ? 'checked' : '') + " " +
  23. (this.props.task.private ? "private" : "");
  24. let result = (
  25. <li className={taskClassName}>
  26. <button className="delete" onClick={this.deleteThisTask}>
  27. &times;
  28. </button>
  29. <input
  30. type="checkbox"
  31. readOnly="{true}"
  32. checked={this.props.task.checked}
  33. onClick={this.toggleChecked}
  34. />
  35. { this.props.showPrivateButton ? (
  36. <button className="toogle-private" onClick={this.togglePrivate}>
  37. {this.props.task.private ? "Private" : "Public"}
  38. </button>
  39. ) : '' }
  40. <strong>{this.props.task.username}</strong>: <span className="text">{this.props.task.text}</span>
  41. </li>
  42. );
  43. return result;
  44. }
  45. });