From 94d5d89aa59b6d1e53dab280c26e3a8fcb22b7e4 Mon Sep 17 00:00:00 2001
From: nsfisis <nsfisis@gmail.com>
Date: Thu, 1 Aug 2024 21:13:11 +0900
Subject: refactor(frontend): provide simpler API client

---
 frontend/app/routes/golf.$gameId.watch.tsx | 30 +++---------------------------
 1 file changed, 3 insertions(+), 27 deletions(-)

(limited to 'frontend/app/routes/golf.$gameId.watch.tsx')

diff --git a/frontend/app/routes/golf.$gameId.watch.tsx b/frontend/app/routes/golf.$gameId.watch.tsx
index c2e269e..1a14e78 100644
--- a/frontend/app/routes/golf.$gameId.watch.tsx
+++ b/frontend/app/routes/golf.$gameId.watch.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 GolfWatchApp from "../components/GolfWatchApp.client";
 import GolfWatchAppConnecting from "../components/GolfWatchApps/GolfWatchAppConnecting";
 
@@ -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.3.1

