GameHeader.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use strict';
  2. const React = require('react/addons');
  3. const Clock = require('./Clock');
  4. const GameHeader = React.createClass({
  5. propTypes: {
  6. io: React.PropTypes.object,
  7. params: React.PropTypes.array.isRequired,
  8. color: React.PropTypes.string,
  9. toggleModal: React.PropTypes.func.isRequired
  10. },
  11. mixins: [React.addons.PureRenderMixin],
  12. render() {
  13. let [_, time, inc] = this.props.params;
  14. return (
  15. <header className="clearfix">
  16. <Clock
  17. io={this.props.io}
  18. params={this.props.params} />
  19. <span id="game-type">
  20. {`${time}|${inc}`}
  21. </span>
  22. <a className="btn" href="/">New game</a>
  23. <button type="button"
  24. className="btn btn--red resign"
  25. onClick={this._onResign}>
  26. Resign
  27. </button>
  28. <button type="button"
  29. className="btn btn--red rematch"
  30. onClick={this._onRematch}>
  31. Rematch
  32. </button>
  33. <a id="chat-icon"
  34. onClick={this._toggleChat}>
  35. <img id="bubble"
  36. src="/img/chat.svg"
  37. width="50"
  38. height="50" />
  39. Chat
  40. </a>
  41. </header>
  42. );
  43. },
  44. _onResign(e) {
  45. let {io, params, color} = this.props;
  46. io.emit('resign', {
  47. token: params[0],
  48. color: color
  49. });
  50. e.preventDefault();
  51. },
  52. _onRematch(e) {
  53. let {io, params, toggleModal} = this.props;
  54. io.emit('rematch-offer', {
  55. token: params[0]
  56. });
  57. toggleModal(true, 'Your offer has been sent.');
  58. e.preventDefault();
  59. },
  60. _toggleChat(e) {
  61. // ChatStore.toggleChat();
  62. e.preventDefault();
  63. }
  64. });
  65. module.exports = GameHeader;