From 2d5f913a431c4223a16c88551ffff4100ac483c4 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 28 Jul 2024 16:01:41 +0900 Subject: feat: implement game entry --- frontend/app/routes/dashboard.tsx | 44 ++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'frontend/app/routes/dashboard.tsx') diff --git a/frontend/app/routes/dashboard.tsx b/frontend/app/routes/dashboard.tsx index 3ad465f..9836d1b 100644 --- a/frontend/app/routes/dashboard.tsx +++ b/frontend/app/routes/dashboard.tsx @@ -1,15 +1,33 @@ import type { LoaderFunctionArgs } from "@remix-run/node"; +import { Link, useLoaderData } from "@remix-run/react"; import { isAuthenticated } from "../.server/auth"; -import { useLoaderData } from "@remix-run/react"; +import { apiClient } from "../.server/api/client"; export async function loader({ request }: LoaderFunctionArgs) { - return await isAuthenticated(request, { + const { user, token } = await isAuthenticated(request, { failureRedirect: "/login", }); + const { data, error } = await apiClient.GET("/games", { + params: { + query: { + player_id: user.user_id, + }, + header: { + Authorization: `Bearer ${token}`, + }, + }, + }); + if (error) { + throw new Error(error.message); + } + return { + user, + games: data.games, + }; } export default function Dashboard() { - const user = useLoaderData()!; + const { user, games } = useLoaderData()!; return (
@@ -24,10 +42,26 @@ export default function Dashboard() {
  • Name: {user.display_name}
  • -

    Game

    +

    Games

      -
    • TODO
    • + {games.map((game) => ( +
    • + {game.display_name}{" "} + {game.state === "closed" || game.state === "finished" ? ( + + Entry + + ) : ( + + Entry + + )} +
    • + ))}
    -- cgit v1.2.3-70-g09d2