From 18308a22879dc9143a03bcbe53cf0c5e8e49ee1f Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 27 Jul 2024 01:17:37 +0900 Subject: remix --- frontend/src/main.tsx | 53 ------- frontend/src/routes/Home.tsx | 13 -- frontend/src/routes/Login.tsx | 36 ----- frontend/src/routes/golf/GolfEntry.tsx | 7 - frontend/src/routes/golf/GolfPlay.tsx | 10 -- frontend/src/routes/golf/GolfWatch.tsx | 10 -- frontend/src/routes/golf/play/App.tsx | 152 --------------------- frontend/src/routes/golf/play/GameState.ts | 7 - frontend/src/routes/golf/play/apps/Connecting.tsx | 8 -- frontend/src/routes/golf/play/apps/Failed.tsx | 8 -- frontend/src/routes/golf/play/apps/Finished.tsx | 27 ---- frontend/src/routes/golf/play/apps/Gaming.tsx | 30 ---- frontend/src/routes/golf/play/apps/Starting.tsx | 13 -- frontend/src/routes/golf/play/apps/Waiting.tsx | 8 -- frontend/src/routes/golf/watch/App.tsx | 111 --------------- frontend/src/routes/golf/watch/WatchState.ts | 7 - frontend/src/routes/golf/watch/apps/Connecting.tsx | 7 - frontend/src/routes/golf/watch/apps/Failed.tsx | 7 - frontend/src/routes/golf/watch/apps/Gaming.tsx | 44 ------ frontend/src/routes/golf/watch/apps/Waiting.tsx | 7 - frontend/src/routes/teams/Edit.tsx | 17 --- frontend/src/routes/teams/New.tsx | 17 --- frontend/src/routes/users/Edit.tsx | 20 --- frontend/src/vite-env.d.ts | 1 - 24 files changed, 620 deletions(-) delete mode 100644 frontend/src/main.tsx delete mode 100644 frontend/src/routes/Home.tsx delete mode 100644 frontend/src/routes/Login.tsx delete mode 100644 frontend/src/routes/golf/GolfEntry.tsx delete mode 100644 frontend/src/routes/golf/GolfPlay.tsx delete mode 100644 frontend/src/routes/golf/GolfWatch.tsx delete mode 100644 frontend/src/routes/golf/play/App.tsx delete mode 100644 frontend/src/routes/golf/play/GameState.ts delete mode 100644 frontend/src/routes/golf/play/apps/Connecting.tsx delete mode 100644 frontend/src/routes/golf/play/apps/Failed.tsx delete mode 100644 frontend/src/routes/golf/play/apps/Finished.tsx delete mode 100644 frontend/src/routes/golf/play/apps/Gaming.tsx delete mode 100644 frontend/src/routes/golf/play/apps/Starting.tsx delete mode 100644 frontend/src/routes/golf/play/apps/Waiting.tsx delete mode 100644 frontend/src/routes/golf/watch/App.tsx delete mode 100644 frontend/src/routes/golf/watch/WatchState.ts delete mode 100644 frontend/src/routes/golf/watch/apps/Connecting.tsx delete mode 100644 frontend/src/routes/golf/watch/apps/Failed.tsx delete mode 100644 frontend/src/routes/golf/watch/apps/Gaming.tsx delete mode 100644 frontend/src/routes/golf/watch/apps/Waiting.tsx delete mode 100644 frontend/src/routes/teams/Edit.tsx delete mode 100644 frontend/src/routes/teams/New.tsx delete mode 100644 frontend/src/routes/users/Edit.tsx delete mode 100644 frontend/src/vite-env.d.ts (limited to 'frontend/src') diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx deleted file mode 100644 index 52b0c29..0000000 --- a/frontend/src/main.tsx +++ /dev/null @@ -1,53 +0,0 @@ -import React from "react"; -import ReactDOM from "react-dom/client"; -import { createBrowserRouter, RouterProvider } from "react-router-dom"; -import Home from "./routes/Home.tsx"; -import Login, { loginAction } from "./routes/Login.tsx"; -import GolfEntry from "./routes/golf/GolfEntry.tsx"; -import GolfPlay from "./routes/golf/GolfPlay.tsx"; -import GolfWatch from "./routes/golf/GolfWatch.tsx"; -import UserEdit from "./routes/users/Edit.tsx"; -import TeamNew from "./routes/teams/New.tsx"; -import TeamEdit from "./routes/teams/Edit.tsx"; - -const router = createBrowserRouter([ - { - path: "/", - element: , - }, - { - path: "/login/", - element: , - action: loginAction, - }, - { - path: "/users/:userId/", - element: , - }, - { - path: "/teams/new/", - element: , - }, - { - path: "/teams/:teamId/", - element: , - }, - { - path: "/golf/entry/", - element: , - }, - { - path: "/golf/:gameId/play/:playerId/", - element: , - }, - { - path: "/golf/:gameId/watch/", - element: , - }, -]); - -ReactDOM.createRoot(document.getElementById("root")!).render( - - - , -); diff --git a/frontend/src/routes/Home.tsx b/frontend/src/routes/Home.tsx deleted file mode 100644 index 176ad35..0000000 --- a/frontend/src/routes/Home.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { Link } from "react-router-dom"; - -export default function Home() { - return ( -
-

Albatross.swift

-

iOSDC 2024

-

- Login -

-
- ); -} diff --git a/frontend/src/routes/Login.tsx b/frontend/src/routes/Login.tsx deleted file mode 100644 index 4871060..0000000 --- a/frontend/src/routes/Login.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import { redirect, Form, ActionFunctionArgs } from "react-router-dom"; - -export default function Login() { - return ( -
-

Albatross.swift

-

Login

-
- - - - - -
-
- ); -} - -export async function loginAction({ request }: ActionFunctionArgs) { - const formData = await request.formData(); - const username = formData.get("username"); - const password = formData.get("password"); - - const res = await fetch("/api/login", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ username, password }), - }); - if (!res.ok) { - throw res; - } - const { userId } = await res.json(); - return redirect(`/users/${userId}/`); -} diff --git a/frontend/src/routes/golf/GolfEntry.tsx b/frontend/src/routes/golf/GolfEntry.tsx deleted file mode 100644 index a0f9c8e..0000000 --- a/frontend/src/routes/golf/GolfEntry.tsx +++ /dev/null @@ -1,7 +0,0 @@ -export default function GolfEntry() { - return ( -
-

Golf Entry

-
- ); -} diff --git a/frontend/src/routes/golf/GolfPlay.tsx b/frontend/src/routes/golf/GolfPlay.tsx deleted file mode 100644 index 42e8e5f..0000000 --- a/frontend/src/routes/golf/GolfPlay.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import App from "./play/App.tsx"; - -export default function GolfPlay() { - return ( -
-

Golf Play

- -
- ); -} diff --git a/frontend/src/routes/golf/GolfWatch.tsx b/frontend/src/routes/golf/GolfWatch.tsx deleted file mode 100644 index acd3305..0000000 --- a/frontend/src/routes/golf/GolfWatch.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import App from "./watch/App.tsx"; - -export default function GolfWatch() { - return ( -
-

Golf Watch

- -
- ); -} diff --git a/frontend/src/routes/golf/play/App.tsx b/frontend/src/routes/golf/play/App.tsx deleted file mode 100644 index b73830a..0000000 --- a/frontend/src/routes/golf/play/App.tsx +++ /dev/null @@ -1,152 +0,0 @@ -import { useState, useEffect } from "react"; -import useWebSocket, { ReadyState } from "react-use-websocket"; -import { useDebouncedCallback } from "use-debounce"; -import Connecting from "./apps/Connecting.tsx"; -import Waiting from "./apps/Waiting.tsx"; -import Starting from "./apps/Starting.tsx"; -import Gaming from "./apps/Gaming.tsx"; -import Finished from "./apps/Finished.tsx"; -import Failed from "./apps/Failed.tsx"; -import type { GameState } from "./GameState.ts"; - -type Props = { - gameId: number; - playerId: number; -}; - -type WebSocketMessage = - | { type: "connect" } - | { type: "prepare"; data: { problem: string } } - | { type: "ready" } - | { type: "start"; data: { startTime: string } } - | { - type: "finish"; - data: { yourScore: number | null; opponentScore: number | null }; - } - | { type: "score"; data: { score: number } } - | { type: "code"; data: { code: string } } - | { - type: "watch"; - data: { - problem: string; - scoreA: number | null; - codeA: string; - scoreB: number | null; - codeB: string; - }; - }; - -export default function App({ gameId, playerId }: Props) { - // const socketUrl = `wss://t.nil.ninja/iosdc/2024/sock/golf/${gameId}/${playerId}/`; - const socketUrl = `ws://localhost:8002/sock/golf/${gameId}/${playerId}/`; - - const { sendJsonMessage, lastJsonMessage, readyState } = - useWebSocket(socketUrl); - - const [gameState, setGameState] = useState("connecting"); - - const [problem, setProblem] = useState(null); - - // in seconds - const [timeLeft, setTimeLeft] = useState(null); - useEffect(() => { - if (gameState === "starting" && timeLeft !== null) { - const timer = setInterval(() => { - setTimeLeft((prevTime) => { - // `prevTime` is not null because `timeLeft` is not null. - prevTime = prevTime!; - if (prevTime <= 1) { - clearInterval(timer); - setGameState("gaming"); - return 0; - } - return prevTime - 1; - }); - }, 1000); - - return () => clearInterval(timer); - } - }, [gameState]); - - const [score, setScore] = useState(null); - - const [result, setResult] = useState<{ - yourScore: number | null; - opponentScore: number | null; - } | null>(null); - - const onCodeChange = useDebouncedCallback((data) => { - sendJsonMessage({ type: "code", data }); - }, 1000); - - useEffect(() => { - if (readyState === ReadyState.UNINSTANTIATED) { - setGameState("failed"); - } else if ( - readyState === ReadyState.CLOSING || - readyState === ReadyState.CLOSED - ) { - if (gameState !== "finished") { - setGameState("failed"); - } - } else if (readyState === ReadyState.CONNECTING) { - setGameState("connecting"); - } else if (readyState === ReadyState.OPEN) { - if (lastJsonMessage !== null) { - if (lastJsonMessage.type === "prepare") { - const { problem } = lastJsonMessage.data; - setProblem(problem); - sendJsonMessage({ type: "ready", data: {} }); - } else if (lastJsonMessage.type === "start") { - const { startTime } = lastJsonMessage.data; - const startTimeMs = Date.parse(startTime); - setTimeLeft( - Math.max(0, Math.floor((startTimeMs - Date.now()) / 1000)), - ); - setGameState("starting"); - } else if (lastJsonMessage.type === "finish") { - const result = lastJsonMessage.data; - setResult(result); - setGameState("finished"); - } else if (lastJsonMessage.type === "score") { - const { score } = lastJsonMessage.data; - setScore(score); - } else { - setGameState("failed"); - } - } else { - setGameState("waiting"); - sendJsonMessage({ type: "connect", data: {} }); - } - } - }, [readyState, lastJsonMessage]); - - return ( -
-

- Game #{gameId} (playerId #{playerId}) -

-
- {gameState === "connecting" ? ( - - ) : gameState === "waiting" ? ( - - ) : gameState === "starting" ? ( - - ) : gameState === "gaming" ? ( - - ) : gameState === "finished" ? ( - - ) : ( - - )} -
-
- ); -} diff --git a/frontend/src/routes/golf/play/GameState.ts b/frontend/src/routes/golf/play/GameState.ts deleted file mode 100644 index 7a1de5c..0000000 --- a/frontend/src/routes/golf/play/GameState.ts +++ /dev/null @@ -1,7 +0,0 @@ -export type GameState = - | "connecting" - | "waiting" - | "starting" - | "gaming" - | "finished" - | "failed"; diff --git a/frontend/src/routes/golf/play/apps/Connecting.tsx b/frontend/src/routes/golf/play/apps/Connecting.tsx deleted file mode 100644 index ead4f03..0000000 --- a/frontend/src/routes/golf/play/apps/Connecting.tsx +++ /dev/null @@ -1,8 +0,0 @@ -type Props = { - gameId: number; - playerId: number; -}; - -export default function Connecting(_props: Props) { - return
接続中です......
; -} diff --git a/frontend/src/routes/golf/play/apps/Failed.tsx b/frontend/src/routes/golf/play/apps/Failed.tsx deleted file mode 100644 index cc1748d..0000000 --- a/frontend/src/routes/golf/play/apps/Failed.tsx +++ /dev/null @@ -1,8 +0,0 @@ -type Props = { - gameId: number; - playerId: number; -}; - -export default function Failed(_props: Props) { - return
エラー
; -} diff --git a/frontend/src/routes/golf/play/apps/Finished.tsx b/frontend/src/routes/golf/play/apps/Finished.tsx deleted file mode 100644 index e04c7a0..0000000 --- a/frontend/src/routes/golf/play/apps/Finished.tsx +++ /dev/null @@ -1,27 +0,0 @@ -type Props = { - gameId: number; - playerId: number; - result: { yourScore: number | null; opponentScore: number | null }; -}; - -export default function Finished({ result }: Props) { - const { yourScore, opponentScore } = result; - const yourScoreToCompare = yourScore ?? Infinity; - const opponentScoreToCompare = opponentScore ?? Infinity; - const resultText = - yourScoreToCompare === opponentScoreToCompare - ? "引き分け" - : yourScoreToCompare < opponentScoreToCompare - ? "あなたの勝ち" - : "あなたの負け"; - return ( - <> -
対戦終了
-
-
{resultText}
-
あなたのスコア: {yourScore ?? "なし"}
-
相手のスコア: {opponentScore ?? "なし"}
-
- - ); -} diff --git a/frontend/src/routes/golf/play/apps/Gaming.tsx b/frontend/src/routes/golf/play/apps/Gaming.tsx deleted file mode 100644 index 9be39c8..0000000 --- a/frontend/src/routes/golf/play/apps/Gaming.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import React from "react"; - -type Props = { - gameId: number; - playerId: number; - problem: string | null; - onCodeChange: (data: { code: string }) => void; - score: number | null; -}; - -export default function Gaming({ problem, onCodeChange, score }: Props) { - const handleTextChange = (e: React.ChangeEvent) => { - onCodeChange({ code: e.target.value }); - }; - - return ( -
-
-
{problem}
-
{score == null ? "Score: -" : `Score: ${score} byte`}
-
-
-