|
@@ -17,7 +17,6 @@ import { gameIdStore } from "../../domain/store";
|
|
|
|
|
|
const initialState = {
|
|
|
gameState: PRE_GAME,
|
|
|
- lastRound: null,
|
|
|
joined: false,
|
|
|
}
|
|
|
|
|
@@ -30,11 +29,9 @@ const extractAndRemoveSearchParam = param => {
|
|
|
}
|
|
|
|
|
|
const Game = () => {
|
|
|
- const [ state, rawSetState ] = useState(initialState);
|
|
|
-
|
|
|
- const setGameState = gameState => rawSetState({ ...state, gameState });
|
|
|
- const setGameStateAnd = (gameState, updates) => rawSetState({ ...state, gameState, ...updates });
|
|
|
- const onGameJoined = () => setGameStateAnd(PRE_ROUND, { joined: true });
|
|
|
+ const [ state, setState ] = useState(initialState);
|
|
|
+ const setGameState = gameState => setState({ ...state, gameState });
|
|
|
+ const onGameJoined = () => setState({ gameState: PRE_ROUND, joined: true });
|
|
|
|
|
|
const joinCode = extractAndRemoveSearchParam("join");
|
|
|
if (joinCode) {
|
|
@@ -52,9 +49,7 @@ const Game = () => {
|
|
|
case PRE_GAME:
|
|
|
return (
|
|
|
<HeaderAndFooter>
|
|
|
- <PreGame
|
|
|
- onGameJoined={onGameJoined}
|
|
|
- />
|
|
|
+ <PreGame onGameJoined={onGameJoined} />
|
|
|
</HeaderAndFooter>
|
|
|
);
|
|
|
case PRE_ROUND:
|
|
@@ -69,23 +64,15 @@ const Game = () => {
|
|
|
);
|
|
|
case IN_ROUND:
|
|
|
return <GamePanel
|
|
|
- onRoundEnd={lastRound => setGameStateAnd(POST_ROUND, { lastRound })}
|
|
|
+ onRoundEnd={() => setGameState(POST_ROUND)}
|
|
|
onGameEnd={() => setGameState(POST_GAME)}
|
|
|
/>
|
|
|
case POST_ROUND:
|
|
|
- return <RoundSummary
|
|
|
- round={state.lastRound}
|
|
|
- onNext={() => setGameState(IN_ROUND)}
|
|
|
- />
|
|
|
+ return <RoundSummary onNext={() => setGameState(IN_ROUND)} />
|
|
|
case POST_GAME:
|
|
|
return (
|
|
|
<HeaderAndFooter>
|
|
|
- <PlayerScores
|
|
|
- onReturnToStart={() => {
|
|
|
- gameIdStore.set(null);
|
|
|
- setGameStateAnd(PRE_GAME, { joined: false });
|
|
|
- }}
|
|
|
- />
|
|
|
+ <PlayerScores onReturnToStart={() => setState(initialState)} />
|
|
|
</HeaderAndFooter>
|
|
|
);
|
|
|
case ERROR:
|