diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-03-20 23:28:39 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-03-20 23:28:39 +0900 |
| commit | 1afd2781818ef5cba0f018811f12cd8653da10b6 (patch) | |
| tree | f04146c6e8753b07d6d29765f615ab9094cd3f54 /frontend/app/components/GolfPlayApp.tsx | |
| parent | a92aa377d536fe67fa1ff485566da38cf94328bb (diff) | |
| download | iosdc-japan-2025-albatross-1afd2781818ef5cba0f018811f12cd8653da10b6.tar.gz iosdc-japan-2025-albatross-1afd2781818ef5cba0f018811f12cd8653da10b6.tar.zst iosdc-japan-2025-albatross-1afd2781818ef5cba0f018811f12cd8653da10b6.zip | |
fix(frontend): fix state corruption
Diffstat (limited to 'frontend/app/components/GolfPlayApp.tsx')
| -rw-r--r-- | frontend/app/components/GolfPlayApp.tsx | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/frontend/app/components/GolfPlayApp.tsx b/frontend/app/components/GolfPlayApp.tsx index 0bb66eb..97f7cc4 100644 --- a/frontend/app/components/GolfPlayApp.tsx +++ b/frontend/app/components/GolfPlayApp.tsx @@ -1,4 +1,5 @@ import { useAtomValue, useSetAtom } from "jotai"; +import { useHydrateAtoms } from "jotai/utils"; import { useContext, useEffect, useState } from "react"; import { useTimer } from "react-use-precision-timer"; import { useDebouncedCallback } from "use-debounce"; @@ -15,6 +16,7 @@ import { handleSubmitCodePostAtom, handleSubmitCodePreAtom, setCurrentTimestampAtom, + setDurationSecondsAtom, setGameStartedAtAtom, setLatestGameStateAtom, } from "../states/play"; @@ -26,14 +28,21 @@ import GolfPlayAppWaiting from "./GolfPlayApps/GolfPlayAppWaiting"; type Game = components["schemas"]["Game"]; type User = components["schemas"]["User"]; +type LatestGameState = components["schemas"]["LatestGameState"]; type Props = { game: Game; player: User; - initialCode: string; + initialGameState: LatestGameState; }; -export default function GolfPlayApp({ game, player, initialCode }: Props) { +export default function GolfPlayApp({ game, player, initialGameState }: Props) { + useHydrateAtoms([ + [setDurationSecondsAtom, game.duration_seconds], + [setGameStartedAtAtom, game.started_at ?? null], + [setLatestGameStateAtom, initialGameState], + ]); + const apiAuthToken = useContext(ApiAuthTokenContext); const gameStateKind = useAtomValue(gameStateKindAtom); @@ -131,7 +140,7 @@ export default function GolfPlayApp({ game, player, initialCode }: Props) { problemTitle={game.problem.title} problemDescription={game.problem.description} sampleCode={game.problem.sample_code} - initialCode={initialCode} + initialCode={initialGameState.code} onCodeChange={onCodeChange} onCodeSubmit={onCodeSubmit} /> |
