diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-03-21 01:54:54 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-03-21 01:54:54 +0900 |
| commit | 4acf8d51b257c30b1a5dd99bd515ac22ddd5b564 (patch) | |
| tree | 495071797a64ab8364061583e7ad61c23bcbfe77 /frontend/app/components/GolfWatchApp.tsx | |
| parent | 338313f3fb97aa96b7cf75596ddcbf55f6a9002d (diff) | |
| download | phperkaigi-2025-albatross-4acf8d51b257c30b1a5dd99bd515ac22ddd5b564.tar.gz phperkaigi-2025-albatross-4acf8d51b257c30b1a5dd99bd515ac22ddd5b564.tar.zst phperkaigi-2025-albatross-4acf8d51b257c30b1a5dd99bd515ac22ddd5b564.zip | |
refactor(frontend): api client
Diffstat (limited to 'frontend/app/components/GolfWatchApp.tsx')
| -rw-r--r-- | frontend/app/components/GolfWatchApp.tsx | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/frontend/app/components/GolfWatchApp.tsx b/frontend/app/components/GolfWatchApp.tsx index 185f41d..cfd5e74 100644 --- a/frontend/app/components/GolfWatchApp.tsx +++ b/frontend/app/components/GolfWatchApp.tsx @@ -2,12 +2,7 @@ import { useAtomValue, useSetAtom } from "jotai"; import { useHydrateAtoms } from "jotai/utils"; import { useContext, useEffect, useState } from "react"; import { useTimer } from "react-use-precision-timer"; -import { - ApiAuthTokenContext, - apiGetGame, - apiGetGameWatchLatestStates, - apiGetGameWatchRanking, -} from "../api/client"; +import { ApiClientContext } from "../api/client"; import type { components } from "../api/schema"; import { gameStateKindAtom, @@ -46,7 +41,7 @@ export default function GolfWatchApp({ [setLatestGameStatesAtom, initialGameStates], ]); - const apiAuthToken = useContext(ApiAuthTokenContext); + const apiClient = useContext(ApiClientContext)!; const gameStateKind = useAtomValue(gameStateKindAtom); const setGameStartedAt = useSetAtom(setGameStartedAtAtom); @@ -88,20 +83,16 @@ export default function GolfWatchApp({ try { if (gameStateKind === "waiting") { - const { game: g } = await apiGetGame(apiAuthToken, game.game_id); + const { game: g } = await apiClient.getGame(game.game_id); if (g.started_at != null) { setGameStartedAt(g.started_at); } } else if (gameStateKind === "gaming") { - const { states } = await apiGetGameWatchLatestStates( - apiAuthToken, + const { states } = await apiClient.getGameWatchLatestStates( game.game_id, ); setLatestGameStates(states); - const { ranking } = await apiGetGameWatchRanking( - apiAuthToken, - game.game_id, - ); + const { ranking } = await apiClient.getGameWatchRanking(game.game_id); setRanking(ranking); } } catch (error) { @@ -116,7 +107,7 @@ export default function GolfWatchApp({ }; }, [ isDataPolling, - apiAuthToken, + apiClient, game.game_id, gameStateKind, setGameStartedAt, |
