Task.jsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. let result = (
  24. <li className={taskClassName}>
  25. <button className="delete" onClick={this.deleteThisTask}>
  26. &times;
  27. </button>
  28. <input
  29. type="checkbox"
  30. readOnly="{true}"
  31. checked={this.props.task.checked}
  32. onClick={this.toggleChecked}
  33. />
  34. { this.props.showPrivateButton ? (
  35. <button className="toogle-private" onClick={this.togglePrivate}>
  36. {this.props.task.private ? "Private" : "Public"}
  37. </button>
  38. ) : '' }
  39. <strong>{this.props.task.username}</strong>: <span className="text">{this.props.task.text}</span>
  40. </li>
  41. );
  42. return result;
  43. }
  44. });