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/routes/golf.$gameId.play.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/routes/golf.$gameId.play.tsx')
| -rw-r--r-- | frontend/app/routes/golf.$gameId.play.tsx | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/frontend/app/routes/golf.$gameId.play.tsx b/frontend/app/routes/golf.$gameId.play.tsx index 4f8468d..8f41257 100644 --- a/frontend/app/routes/golf.$gameId.play.tsx +++ b/frontend/app/routes/golf.$gameId.play.tsx @@ -3,11 +3,7 @@ import { useMemo } from "react"; import type { LoaderFunctionArgs, MetaFunction } from "react-router"; import { useLoaderData } from "react-router"; import { ensureUserLoggedIn } from "../.server/auth"; -import { - ApiAuthTokenContext, - apiGetGame, - apiGetGamePlayLatestState, -} from "../api/client"; +import { ApiClientContext, createApiClient } from "../api/client"; import GolfPlayApp from "../components/GolfPlayApp"; export const meta: MetaFunction<typeof loader> = ({ data }) => [ @@ -20,29 +16,25 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => [ export async function loader({ params, request }: LoaderFunctionArgs) { const { token, user } = await ensureUserLoggedIn(request); + const apiClient = createApiClient(token); const gameId = Number(params.gameId); - const fetchGame = async () => { - return (await apiGetGame(token, gameId)).game; - }; - const fetchGameState = async () => { - return (await apiGetGamePlayLatestState(token, gameId)).state; - }; - - const [game, state] = await Promise.all([fetchGame(), fetchGameState()]); + const [{ game }, { state: gameState }] = await Promise.all([ + apiClient.getGame(gameId), + apiClient.getGamePlayLatestState(gameId), + ]); return { - apiAuthToken: token, + apiToken: token, game, player: user, - gameState: state, + gameState, }; } export default function GolfPlay() { - const { apiAuthToken, game, player, gameState } = - useLoaderData<typeof loader>(); + const { apiToken, game, player, gameState } = useLoaderData<typeof loader>(); const store = useMemo(() => { void game.game_id; @@ -52,14 +44,14 @@ export default function GolfPlay() { return ( <JotaiProvider store={store}> - <ApiAuthTokenContext.Provider value={apiAuthToken}> + <ApiClientContext.Provider value={createApiClient(apiToken)}> <GolfPlayApp key={game.game_id} game={game} player={player} initialGameState={gameState} /> - </ApiAuthTokenContext.Provider> + </ApiClientContext.Provider> </JotaiProvider> ); } |
