aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-04 17:06:23 +0900
committernsfisis <nsfisis@gmail.com>2024-08-04 17:06:23 +0900
commitdd3440009ae75ecc00e10e48b014ef23bb446964 (patch)
tree487566e4fe6b7f77e95bbf3e25e02a0534e78177 /frontend
parent264fa15fb2ba5f0b9636cda44b64deb3c56aa99d (diff)
downloadiosdc-japan-2024-albatross-dd3440009ae75ecc00e10e48b014ef23bb446964.tar.gz
iosdc-japan-2024-albatross-dd3440009ae75ecc00e10e48b014ef23bb446964.tar.zst
iosdc-japan-2024-albatross-dd3440009ae75ecc00e10e48b014ef23bb446964.zip
feat(frontend): remove admin pages
Diffstat (limited to 'frontend')
-rw-r--r--frontend/app/.server/auth.ts10
-rw-r--r--frontend/app/routes/admin.dashboard.tsx29
-rw-r--r--frontend/app/routes/admin.games.tsx35
-rw-r--r--frontend/app/routes/admin.games_.$gameId.tsx95
-rw-r--r--frontend/app/routes/admin.tsx8
-rw-r--r--frontend/app/routes/admin.users.tsx34
6 files changed, 0 insertions, 211 deletions
diff --git a/frontend/app/.server/auth.ts b/frontend/app/.server/auth.ts
index a4811e2..d5ffe0f 100644
--- a/frontend/app/.server/auth.ts
+++ b/frontend/app/.server/auth.ts
@@ -40,16 +40,6 @@ export async function ensureUserLoggedIn(
return { user, token };
}
-export async function ensureAdminUserLoggedIn(
- request: Request | Session,
-): Promise<{ user: User; token: string }> {
- const { user, token } = await ensureUserLoggedIn(request);
- if (!user.is_admin) {
- throw new Error("Forbidden");
- }
- return { user, token };
-}
-
export async function ensureUserNotLoggedIn(
request: Request | Session,
): Promise<null> {
diff --git a/frontend/app/routes/admin.dashboard.tsx b/frontend/app/routes/admin.dashboard.tsx
deleted file mode 100644
index 8a0c9a8..0000000
--- a/frontend/app/routes/admin.dashboard.tsx
+++ /dev/null
@@ -1,29 +0,0 @@
-import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
-import { Form, Link } from "@remix-run/react";
-import { ensureAdminUserLoggedIn } from "../.server/auth";
-
-export const meta: MetaFunction = () => [
- { title: "[Admin] Dashboard | iOSDC Japan 2024 Albatross.swift" },
-];
-
-export async function loader({ request }: LoaderFunctionArgs) {
- await ensureAdminUserLoggedIn(request);
- return null;
-}
-
-export default function AdminDashboard() {
- return (
- <div>
- <h1>[Admin] Dashboard</h1>
- <p>
- <Link to="/admin/users">Users</Link>
- </p>
- <p>
- <Link to="/admin/games">Games</Link>
- </p>
- <Form method="post" action="/logout">
- <button type="submit">Logout</button>
- </Form>
- </div>
- );
-}
diff --git a/frontend/app/routes/admin.games.tsx b/frontend/app/routes/admin.games.tsx
deleted file mode 100644
index f9d15f7..0000000
--- a/frontend/app/routes/admin.games.tsx
+++ /dev/null
@@ -1,35 +0,0 @@
-import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
-import { Link, useLoaderData } from "@remix-run/react";
-import { adminApiGetGames } from "../.server/api/client";
-import { ensureAdminUserLoggedIn } from "../.server/auth";
-
-export const meta: MetaFunction = () => [
- { title: "[Admin] Games | iOSDC Japan 2024 Albatross.swift" },
-];
-
-export async function loader({ request }: LoaderFunctionArgs) {
- const { token } = await ensureAdminUserLoggedIn(request);
- const { games } = await adminApiGetGames(token);
- return { games };
-}
-
-export default function AdminGames() {
- const { games } = useLoaderData<typeof loader>()!;
-
- return (
- <div>
- <div>
- <h1>[Admin] Games</h1>
- <ul>
- {games.map((game) => (
- <li key={game.game_id}>
- <Link to={`/admin/games/${game.game_id}`}>
- {game.display_name} (id={game.game_id})
- </Link>
- </li>
- ))}
- </ul>
- </div>
- </div>
- );
-}
diff --git a/frontend/app/routes/admin.games_.$gameId.tsx b/frontend/app/routes/admin.games_.$gameId.tsx
deleted file mode 100644
index c4d75c1..0000000
--- a/frontend/app/routes/admin.games_.$gameId.tsx
+++ /dev/null
@@ -1,95 +0,0 @@
-import type {
- ActionFunctionArgs,
- LoaderFunctionArgs,
- MetaFunction,
-} from "@remix-run/node";
-import { Form, useLoaderData } from "@remix-run/react";
-import { adminApiGetGame, adminApiPutGame } from "../.server/api/client";
-import { ensureAdminUserLoggedIn } from "../.server/auth";
-
-export const meta: MetaFunction<typeof loader> = ({ data }) => [
- {
- title: data
- ? `[Admin] Game Edit ${data.game.display_name} | iOSDC Japan 2024 Albatross.swift`
- : "[Admin] Game Edit | iOSDC Japan 2024 Albatross.swift",
- },
-];
-
-export async function loader({ request, params }: LoaderFunctionArgs) {
- const { token } = await ensureAdminUserLoggedIn(request);
- const { gameId } = params;
- const { game } = await adminApiGetGame(token, Number(gameId));
- return { game };
-}
-
-export async function action({ request, params }: ActionFunctionArgs) {
- const { token } = await ensureAdminUserLoggedIn(request);
- const { gameId } = params;
-
- const formData = await request.formData();
- const action = formData.get("action");
-
- const nextState =
- action === "open"
- ? "waiting_entries"
- : action === "start"
- ? "prepare"
- : null;
- if (!nextState) {
- throw new Error("Invalid action");
- }
-
- await adminApiPutGame(token, Number(gameId), {
- state: nextState,
- });
- return null;
-}
-
-export default function AdminGameEdit() {
- const { game } = useLoaderData<typeof loader>()!;
-
- return (
- <div>
- <div>
- <h1>[Admin] Game Edit {game.display_name}</h1>
- <ul>
- <li>ID: {game.game_id}</li>
- <li>State: {game.state}</li>
- <li>Display Name: {game.display_name}</li>
- <li>Duration Seconds: {game.duration_seconds}</li>
- <li>
- Started At:{" "}
- {game.started_at
- ? new Date(game.started_at * 1000).toString()
- : "-"}
- </li>
- <li>Problem ID: {game.problem ? game.problem.problem_id : "-"}</li>
- </ul>
- <div>
- <Form method="post">
- <div>
- <button
- type="submit"
- name="action"
- value="open"
- disabled={game.state !== "closed"}
- >
- Open
- </button>
- </div>
- <div>
- <button
- type="submit"
- name="action"
- value="start"
- disabled={game.state !== "waiting_start"}
- >
- Start
- </button>
- </div>
- </Form>
- </div>
- </div>
- </div>
- );
-}
diff --git a/frontend/app/routes/admin.tsx b/frontend/app/routes/admin.tsx
deleted file mode 100644
index ceef37e..0000000
--- a/frontend/app/routes/admin.tsx
+++ /dev/null
@@ -1,8 +0,0 @@
-import type { LinksFunction } from "@remix-run/node";
-import normalizeCss from "sakura.css/css/normalize.css?url";
-import sakuraCss from "sakura.css/css/sakura.css?url";
-
-export const links: LinksFunction = () => [
- { rel: "stylesheet", href: normalizeCss },
- { rel: "stylesheet", href: sakuraCss },
-];
diff --git a/frontend/app/routes/admin.users.tsx b/frontend/app/routes/admin.users.tsx
deleted file mode 100644
index c403285..0000000
--- a/frontend/app/routes/admin.users.tsx
+++ /dev/null
@@ -1,34 +0,0 @@
-import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
-import { useLoaderData } from "@remix-run/react";
-import { adminApiGetUsers } from "../.server/api/client";
-import { ensureAdminUserLoggedIn } from "../.server/auth";
-
-export const meta: MetaFunction = () => [
- { title: "[Admin] Users | iOSDC Japan 2024 Albatross.swift" },
-];
-
-export async function loader({ request }: LoaderFunctionArgs) {
- const { token } = await ensureAdminUserLoggedIn(request);
- const { users } = await adminApiGetUsers(token);
- return { users };
-}
-
-export default function AdminUsers() {
- const { users } = useLoaderData<typeof loader>()!;
-
- return (
- <div>
- <div>
- <h1>[Admin] Users</h1>
- <ul>
- {users.map((user) => (
- <li key={user.user_id}>
- {user.display_name} (id={user.user_id} username={user.username})
- {user.is_admin && <span> admin</span>}
- </li>
- ))}
- </ul>
- </div>
- </div>
- );
-}