aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/components/GolfPlayApp.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app/components/GolfPlayApp.tsx')
-rw-r--r--frontend/app/components/GolfPlayApp.tsx15
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}
/>