GamePanel.jsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React, { useState } from 'react';
  2. import { sendGuess } from "../../../domain/GGSHService";
  3. import Loading from '../../util/Loading';
  4. import GuessPane from "./GuessPane";
  5. import PositionedStreetView from "./PositionedStreetView";
  6. import useRoundInfo from "./useRoundInfo";
  7. const GamePanelContainer = ({ gameId, playerName, onRoundEnd, onGameEnd }) => {
  8. const [submitDisabled, setSubmitDisabled] = useState(false);
  9. const [selectedPoint, setSelectedPoint] = useState(null);
  10. const [finished, roundInfo] = useRoundInfo(gameId, playerName);
  11. if (finished) {
  12. onGameEnd();
  13. return <Loading/>
  14. }
  15. const { currentRound, targetPoint, roundSeconds } = roundInfo;
  16. if (!currentRound || !targetPoint || !roundSeconds) {
  17. return <Loading/>
  18. }
  19. const handleSubmitGuess = async () => {
  20. setSubmitDisabled(true);
  21. const { score, totalScore } = await sendGuess(gameId, playerName, currentRound, selectedPoint || { timeout: true });
  22. onRoundEnd({
  23. roundNum: currentRound,
  24. selectedPoint,
  25. targetPoint,
  26. score,
  27. totalScore,
  28. });
  29. }
  30. return (
  31. <div className="game-panel">
  32. <div className="game-panel__streetview">
  33. <PositionedStreetView position={targetPoint} />
  34. </div>
  35. <GuessPane
  36. roundSeconds={roundSeconds}
  37. onTimeout={handleSubmitGuess}
  38. onSelectPoint={setSelectedPoint}
  39. onSubmitGuess={handleSubmitGuess}
  40. submitDisabled={submitDisabled || selectedPoint === null}
  41. />
  42. </div>
  43. );
  44. }
  45. export default GamePanelContainer;