aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-03-21 15:11:30 +0900
committernsfisis <nsfisis@gmail.com>2025-03-21 15:40:40 +0900
commit432baae1b49343ea780793330149a285a53bbdc7 (patch)
tree3dc84e517910fb7e15f172bab5a803a6379a7c32 /frontend/app
parent589d2355910e8fc63eabecad631b16b3d3d6a492 (diff)
downloadphperkaigi-2025-albatross-432baae1b49343ea780793330149a285a53bbdc7.tar.gz
phperkaigi-2025-albatross-432baae1b49343ea780793330149a285a53bbdc7.tar.zst
phperkaigi-2025-albatross-432baae1b49343ea780793330149a285a53bbdc7.zip
wip
Diffstat (limited to 'frontend/app')
-rw-r--r--frontend/app/.server/auth.ts2
-rw-r--r--frontend/app/components/GolfPlayApp.tsx2
-rw-r--r--frontend/app/routes/golf.$gameId.play.tsx28
-rw-r--r--frontend/app/routes/golf.$gameId.watch.tsx30
4 files changed, 35 insertions, 27 deletions
diff --git a/frontend/app/.server/auth.ts b/frontend/app/.server/auth.ts
index d56c193..3e24638 100644
--- a/frontend/app/.server/auth.ts
+++ b/frontend/app/.server/auth.ts
@@ -1,4 +1,4 @@
-import { jwtDecode, type JwtPayload } from "jwt-decode";
+import { type JwtPayload, jwtDecode } from "jwt-decode";
import { redirect } from "react-router";
import { Authenticator } from "remix-auth";
import { FormStrategy } from "remix-auth-form";
diff --git a/frontend/app/components/GolfPlayApp.tsx b/frontend/app/components/GolfPlayApp.tsx
index 9ba3818..e74edc7 100644
--- a/frontend/app/components/GolfPlayApp.tsx
+++ b/frontend/app/components/GolfPlayApp.tsx
@@ -68,7 +68,7 @@ export default function GolfPlayApp({ game, player, initialGameState }: Props) {
console.log("player:c2s:submit");
handleSubmitCodePre();
await apiClient.postGamePlaySubmit(game.game_id, code);
- await new Promise((resolve) => setTimeout(resolve, 2000));
+ await new Promise((resolve) => setTimeout(resolve, 1000));
handleSubmitCodePost();
},
1000,
diff --git a/frontend/app/routes/golf.$gameId.play.tsx b/frontend/app/routes/golf.$gameId.play.tsx
index 8f41257..d9907aa 100644
--- a/frontend/app/routes/golf.$gameId.play.tsx
+++ b/frontend/app/routes/golf.$gameId.play.tsx
@@ -1,7 +1,7 @@
import { Provider as JotaiProvider, createStore } from "jotai";
import { useMemo } from "react";
import type { LoaderFunctionArgs, MetaFunction } from "react-router";
-import { useLoaderData } from "react-router";
+import { redirect, useLoaderData } from "react-router";
import { ensureUserLoggedIn } from "../.server/auth";
import { ApiClientContext, createApiClient } from "../api/client";
import GolfPlayApp from "../components/GolfPlayApp";
@@ -20,17 +20,21 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
const gameId = Number(params.gameId);
- const [{ game }, { state: gameState }] = await Promise.all([
- apiClient.getGame(gameId),
- apiClient.getGamePlayLatestState(gameId),
- ]);
-
- return {
- apiToken: token,
- game,
- player: user,
- gameState,
- };
+ try {
+ const [{ game }, { state: gameState }] = await Promise.all([
+ apiClient.getGame(gameId),
+ apiClient.getGamePlayLatestState(gameId),
+ ]);
+
+ return {
+ apiToken: token,
+ game,
+ player: user,
+ gameState,
+ };
+ } catch {
+ throw redirect("/dashboard");
+ }
}
export default function GolfPlay() {
diff --git a/frontend/app/routes/golf.$gameId.watch.tsx b/frontend/app/routes/golf.$gameId.watch.tsx
index 07e8c9e..556eb03 100644
--- a/frontend/app/routes/golf.$gameId.watch.tsx
+++ b/frontend/app/routes/golf.$gameId.watch.tsx
@@ -1,7 +1,7 @@
import { Provider as JotaiProvider, createStore } from "jotai";
import { useMemo } from "react";
import type { LoaderFunctionArgs, MetaFunction } from "react-router";
-import { useLoaderData } from "react-router";
+import { redirect, useLoaderData } from "react-router";
import { ensureUserLoggedIn } from "../.server/auth";
import { ApiClientContext, createApiClient } from "../api/client";
import GolfWatchApp from "../components/GolfWatchApp";
@@ -20,18 +20,22 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
const gameId = Number(params.gameId);
- const [{ game }, { ranking }, { states: gameStates }] = await Promise.all([
- await apiClient.getGame(gameId),
- await apiClient.getGameWatchRanking(gameId),
- await apiClient.getGameWatchLatestStates(gameId),
- ]);
-
- return {
- apiToken: token,
- game,
- ranking,
- gameStates,
- };
+ try {
+ const [{ game }, { ranking }, { states: gameStates }] = await Promise.all([
+ await apiClient.getGame(gameId),
+ await apiClient.getGameWatchRanking(gameId),
+ await apiClient.getGameWatchLatestStates(gameId),
+ ]);
+
+ return {
+ apiToken: token,
+ game,
+ ranking,
+ gameStates,
+ };
+ } catch {
+ throw redirect("/dashboard");
+ }
}
export default function GolfWatch() {