67 lines
1.5 KiB
JavaScript
67 lines
1.5 KiB
JavaScript
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;
|