From 94d5d89aa59b6d1e53dab280c26e3a8fcb22b7e4 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 1 Aug 2024 21:13:11 +0900 Subject: refactor(frontend): provide simpler API client --- frontend/app/routes/golf.$gameId.play.tsx | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) (limited to 'frontend/app/routes/golf.$gameId.play.tsx') diff --git a/frontend/app/routes/golf.$gameId.play.tsx b/frontend/app/routes/golf.$gameId.play.tsx index 919d8df..248c4e4 100644 --- a/frontend/app/routes/golf.$gameId.play.tsx +++ b/frontend/app/routes/golf.$gameId.play.tsx @@ -2,7 +2,7 @@ import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node"; import { useLoaderData } from "@remix-run/react"; import { ClientOnly } from "remix-utils/client-only"; import { isAuthenticated } from "../.server/auth"; -import { apiClient } from "../.server/api/client"; +import { apiGetGame, apiGetToken } from "../.server/api/client"; import GolfPlayApp from "../components/GolfPlayApp.client"; import GolfPlayAppConnecting from "../components/GolfPlayApps/GolfPlayAppConnecting"; @@ -22,34 +22,10 @@ export async function loader({ params, request }: LoaderFunctionArgs) { }); const fetchGame = async () => { - const { data, error } = await apiClient.GET("/games/{game_id}", { - params: { - path: { - game_id: Number(params.gameId), - }, - header: { - Authorization: `Bearer ${token}`, - }, - }, - }); - if (error) { - throw new Error(error.message); - } - return data.game; + return (await apiGetGame(token, Number(params.gameId))).game; }; - const fetchSockToken = async () => { - const { data, error } = await apiClient.GET("/token", { - params: { - header: { - Authorization: `Bearer ${token}`, - }, - }, - }); - if (error) { - throw new Error(error.message); - } - return data.token; + return (await apiGetToken(token)).token; }; const [game, sockToken] = await Promise.all([fetchGame(), fetchSockToken()]); -- cgit v1.2.3-70-g09d2