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/admin.games_.$gameId.tsx | 35 ++++------------------------
 1 file changed, 5 insertions(+), 30 deletions(-)

(limited to 'frontend/app/routes/admin.games_.$gameId.tsx')

diff --git a/frontend/app/routes/admin.games_.$gameId.tsx b/frontend/app/routes/admin.games_.$gameId.tsx
index ff8f136..1ad8a2a 100644
--- a/frontend/app/routes/admin.games_.$gameId.tsx
+++ b/frontend/app/routes/admin.games_.$gameId.tsx
@@ -5,7 +5,7 @@ import type {
 } from "@remix-run/node";
 import { useLoaderData, Form } from "@remix-run/react";
 import { isAuthenticated } from "../.server/auth";
-import { apiClient } from "../.server/api/client";
+import { adminApiPutGame, adminApiGetGame } from "../.server/api/client";
 
 export const meta: MetaFunction<typeof loader> = ({ data }) => {
   return [
@@ -25,20 +25,8 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
     throw new Error("Unauthorized");
   }
   const { gameId } = params;
-  const { data, error } = await apiClient.GET("/admin/games/{game_id}", {
-    params: {
-      path: {
-        game_id: Number(gameId),
-      },
-      header: {
-        Authorization: `Bearer ${token}`,
-      },
-    },
-  });
-  if (error) {
-    throw new Error(error.message);
-  }
-  return { game: data.game };
+  const { game } = await adminApiGetGame(token, Number(gameId));
+  return { game };
 }
 
 export async function action({ request, params }: ActionFunctionArgs) {
@@ -63,22 +51,9 @@ export async function action({ request, params }: ActionFunctionArgs) {
     throw new Error("Invalid action");
   }
 
-  const { error } = await apiClient.PUT("/admin/games/{game_id}", {
-    params: {
-      path: {
-        game_id: Number(gameId),
-      },
-      header: {
-        Authorization: `Bearer ${token}`,
-      },
-    },
-    body: {
-      state: nextState,
-    },
+  await adminApiPutGame(token, Number(gameId), {
+    state: nextState,
   });
-  if (error) {
-    throw new Error(error.message);
-  }
   return null;
 }
 
-- 
cgit v1.2.3-70-g09d2

