Task.jsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. render() {
  16. // Give tasks a different clasSName when they are checked off,
  17. // so that we can style them nicely in CSS.
  18. const taskClassName = this.props.task.checked ? 'checked' : '';
  19. let result = (
  20. <li className={taskClassName}>
  21. <button className="delete" onClick={this.deleteThisTask}>
  22. &times;
  23. </button>
  24. <input
  25. type="checkbox"
  26. readOnly="{true}"
  27. checked={this.props.task.checked}
  28. onClick={this.toggleChecked}
  29. />
  30. { this.props.showPrivateButton ? (
  31. <button className="toogle-private" onClick={this.togglePrivate}>
  32. {this.props.task.private ? "Private" : "Public"}
  33. </button>
  34. ) : '' }
  35. <strong>{this.props.task.username}</strong>: <span className="text">{this.props.task.text}</span>
  36. </li>
  37. );
  38. return result;
  39. }
  40. });