12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import React from "react";
- import ConfirmBattle from "../components/ConfirmBattle";
- import githubHelpers from "../utils/githubHelpers";
- class ConfirmBattleContainer extends React.Component {
- constructor(props) {
- console.log("Constructor (getInitialState)");
- super(props);
- this.state = {
- isLoading: true,
- playerInfo: []
- };
- this.handleInitiateBattle = this.handleInitiateBattle.bind(this);
- }
- componentWillMount() {
- // console.log("componentWillMount");
- }
- componentDidMount() {
- // console.log("componentDidMount");
- const query = this.props.location.query;
- // Fetch info from Github then update state.
- githubHelpers.getPlayersInfo([query.playerOne, query.playerTwo])
- .then((info) => {
- this.setState({
- isLoading: false,
- playerInfo: info
- });
- });
- }
- componentWillReceiveProps() {
- console.log("componentWillReceiveProps");
- }
- componentWillUnmount() {
- console.log("componentWillUnmount");
- }
- handleInitiateBattle() {
- console.log("Handling initiate battle");
- this.context.router.push({
- pathname: "/results",
- state: {
- playerInfo: this.state.playerInfo
- }
- });
- }
- render() {
- return (
- <ConfirmBattle
- isLoading={this.state.isLoading}
- onInitiateBattle={this.handleInitiateBattle}
- playerInfo={this.state.playerInfo}
- />
- );
- }
- }
- ConfirmBattleContainer.contextTypes = {
- router: React.PropTypes.object.isRequired
- };
- export default ConfirmBattleContainer;
|