|
@@ -1,12 +1,12 @@
|
|
|
import React from 'react';
|
|
|
-import { createGame, gameInfo, joinGame, getGuesses, sendGuess } from "./services/ggsh.service";
|
|
|
+import { getGoogleApiKey, createGame, gameInfo, joinGame, getGuesses, sendGuess } from "./services/ggsh.service";
|
|
|
import GamePanel from "./components/game-panel.component";
|
|
|
import ApiInfo from "./components/api-info.component";
|
|
|
import PlayerScores from "./components/player-scores.component";
|
|
|
import RoundSummary from './components/round-summary.component';
|
|
|
-import './App.css';
|
|
|
import PreGame from './components/pre-game.component';
|
|
|
import PreRound from './components/pre-round.component';
|
|
|
+import './App.css';
|
|
|
|
|
|
const LOADING = "LOADING"; // Application is loading
|
|
|
const PRE_GAME = "PREGAME"; // Game is not yet started
|
|
@@ -20,7 +20,8 @@ class Game extends React.Component {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
this.state = {
|
|
|
- gameState: PRE_GAME,
|
|
|
+ googleApiKey: null,
|
|
|
+ gameState: LOADING,
|
|
|
playerName: null,
|
|
|
gameId: null,
|
|
|
currentRound: null,
|
|
@@ -35,6 +36,11 @@ class Game extends React.Component {
|
|
|
|
|
|
// TODO error handling throughout - at the moment it assumes all calls always succeed
|
|
|
|
|
|
+ async componentDidMount() {
|
|
|
+ const googleApiKey = await getGoogleApiKey();
|
|
|
+ this.setState({ googleApiKey, gameState: PRE_GAME });
|
|
|
+ }
|
|
|
+
|
|
|
async handleCreateGame() {
|
|
|
this.setState({ gameState: LOADING });
|
|
|
const { playerName } = this.state;
|
|
@@ -95,11 +101,12 @@ class Game extends React.Component {
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
- const {
|
|
|
- gameState,
|
|
|
- gameId,
|
|
|
- playerName,
|
|
|
- targetPoint,
|
|
|
+ const {
|
|
|
+ googleApiKey,
|
|
|
+ gameState,
|
|
|
+ gameId,
|
|
|
+ playerName,
|
|
|
+ targetPoint,
|
|
|
selectedPoint,
|
|
|
} = this.state;
|
|
|
|
|
@@ -124,6 +131,7 @@ class Game extends React.Component {
|
|
|
case IN_ROUND:
|
|
|
const { roundTimer } = this.state;
|
|
|
return <GamePanel
|
|
|
+ googleApiKey={googleApiKey}
|
|
|
onSelectPoint={latLng => this.setState({selectedPoint: latLng})}
|
|
|
onSubmitGuess={() => this.handleSubmitGuess()}
|
|
|
streetViewPoint={targetPoint}
|
|
@@ -134,6 +142,7 @@ class Game extends React.Component {
|
|
|
case POST_ROUND:
|
|
|
const { currentRound, lastScore, totalScore } = this.state;
|
|
|
return <RoundSummary
|
|
|
+ googleApiKey={googleApiKey}
|
|
|
roundNum={currentRound}
|
|
|
score={lastScore}
|
|
|
totalScore={totalScore}
|
|
@@ -153,7 +162,7 @@ class Game extends React.Component {
|
|
|
default:
|
|
|
this.setState({ gameState: ERROR });
|
|
|
return <p>Application state is inconsistent, please refresh and rejoin your previous game.</p>
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|