useRoundInfo.jsx 687 B

123456789101112131415161718192021
  1. import { useState, useEffect } from 'react';
  2. import { getCurrentRound } from "../../../domain/GGSHService";
  3. export default (gameId, playerName) => {
  4. const [finished, setFinished] = useState(false);
  5. const [roundInfo, setRoundInfo] = useState({currentRound: null, targetPoint: null, roundSeconds: null});
  6. useEffect(() => {
  7. const setup = async () => {
  8. const { currentRound, coord, timer } = await getCurrentRound(gameId, playerName);
  9. if (currentRound) {
  10. setRoundInfo({ currentRound, targetPoint: coord, roundSeconds: timer });
  11. } else {
  12. setFinished(true);
  13. }
  14. }
  15. setup();
  16. }, [gameId, playerName]);
  17. return [finished, roundInfo];
  18. }