From d73fd8bf5bf589a4a391c867e980761fadb647ce Mon Sep 17 00:00:00 2001
From: nsfisis <nsfisis@gmail.com>
Date: Mon, 29 Jul 2024 03:44:10 +0900
Subject: feat: partially implement watching

---
 frontend/app/routes/golf.$gameId.watch.tsx | 33 ++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 frontend/app/routes/golf.$gameId.watch.tsx

(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
new file mode 100644
index 0000000..e1cb5d7
--- /dev/null
+++ b/frontend/app/routes/golf.$gameId.watch.tsx
@@ -0,0 +1,33 @@
+import type { LoaderFunctionArgs } from "@remix-run/node";
+import { isAuthenticated } from "../.server/auth";
+import { apiClient } from "../.server/api/client";
+import { useLoaderData } from "@remix-run/react";
+import GolfWatchApp from "../components/GolfWatchApp";
+
+export async function loader({ params, request }: LoaderFunctionArgs) {
+  const { token } = await isAuthenticated(request, {
+    failureRedirect: "/login",
+  });
+  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 {
+    game: data,
+  };
+}
+
+export default function GolfWatch() {
+  const { game } = useLoaderData<typeof loader>();
+
+  return <GolfWatchApp game={game} />;
+}
-- 
cgit v1.2.3-70-g09d2

