|
@@ -1,28 +1,21 @@
|
|
|
-import React, { useState, useEffect } from 'react';
|
|
|
-import { gameInfo, getGuesses, sendGuess } from "../../../domain/GGSHService";
|
|
|
+import React, { useState } from 'react';
|
|
|
+import { sendGuess } from "../../../domain/GGSHService";
|
|
|
import Loading from '../../util/Loading';
|
|
|
import GuessPane from "./GuessPane";
|
|
|
import PositionedStreetView from "./PositionedStreetView";
|
|
|
+import useRoundInfo from "../../../hooks/useRoundInfo";
|
|
|
|
|
|
const GamePanelContainer = ({ gameId, playerName, onRoundEnd, onGameEnd }) => {
|
|
|
- const [{ currentRound, targetPoint, roundSeconds }, setRoundInfo] = useState({currentRound: null, targetPoint: null, roundSeconds: null});
|
|
|
const [submitDisabled, setSubmitDisabled] = useState(false);
|
|
|
const [selectedPoint, setSelectedPoint] = useState(null);
|
|
|
+ const [finished, roundInfo] = useRoundInfo(gameId, playerName);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- const setup = async () => {
|
|
|
- const { currentRound } = await getGuesses(gameId, playerName);
|
|
|
- if (currentRound) {
|
|
|
- const { coords, timer } = await gameInfo(gameId);
|
|
|
- const targetPoint = coords[currentRound];
|
|
|
- setRoundInfo({ currentRound, targetPoint, roundSeconds: timer });
|
|
|
- } else {
|
|
|
- onGameEnd();
|
|
|
- }
|
|
|
- }
|
|
|
- setup();
|
|
|
- }, [gameId, playerName, onGameEnd]);
|
|
|
+ if (finished) {
|
|
|
+ onGameEnd();
|
|
|
+ return <Loading/>
|
|
|
+ }
|
|
|
|
|
|
+ const { currentRound, targetPoint, roundSeconds } = roundInfo;
|
|
|
if (!currentRound || !targetPoint || !roundSeconds) {
|
|
|
return <Loading/>
|
|
|
}
|