ConfirmBattleContainer.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React from "react";
  2. import ConfirmBattle from "../components/ConfirmBattle";
  3. import githubHelpers from "../utils/githubHelpers";
  4. class ConfirmBattleContainer extends React.Component {
  5. constructor(props) {
  6. console.log("Constructor (getInitialState)");
  7. super(props);
  8. this.state = {
  9. isLoading: true,
  10. playerInfo: []
  11. };
  12. this.handleInitiateBattle = this.handleInitiateBattle.bind(this);
  13. }
  14. componentWillMount() {
  15. // console.log("componentWillMount");
  16. }
  17. componentDidMount() {
  18. // console.log("componentDidMount");
  19. const query = this.props.location.query;
  20. // Fetch info from Github then update state.
  21. githubHelpers.getPlayersInfo([query.playerOne, query.playerTwo])
  22. .then((info) => {
  23. this.setState({
  24. isLoading: false,
  25. playerInfo: info
  26. });
  27. });
  28. }
  29. componentWillReceiveProps() {
  30. console.log("componentWillReceiveProps");
  31. }
  32. componentWillUnmount() {
  33. console.log("componentWillUnmount");
  34. }
  35. handleInitiateBattle() {
  36. console.log("Handling initiate battle");
  37. this.context.router.push({
  38. pathname: "/results",
  39. state: {
  40. playerInfo: this.state.playerInfo
  41. }
  42. });
  43. }
  44. render() {
  45. return (
  46. <ConfirmBattle
  47. isLoading={this.state.isLoading}
  48. onInitiateBattle={this.handleInitiateBattle}
  49. playerInfo={this.state.playerInfo}
  50. />
  51. );
  52. }
  53. }
  54. ConfirmBattleContainer.contextTypes = {
  55. router: React.PropTypes.object.isRequired
  56. };
  57. export default ConfirmBattleContainer;