diff options
Diffstat (limited to 'frontend/app')
16 files changed, 123 insertions, 102 deletions
diff --git a/frontend/app/components/Gaming/ExecStatusIndicatorIcon.tsx b/frontend/app/components/Gaming/ExecStatusIndicatorIcon.tsx index b611c5d..a717a48 100644 --- a/frontend/app/components/Gaming/ExecStatusIndicatorIcon.tsx +++ b/frontend/app/components/Gaming/ExecStatusIndicatorIcon.tsx @@ -6,7 +6,7 @@ import { faRotate, } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import type { ExecResultStatus } from "../../models/ExecResult"; +import type { ExecResultStatus } from "../../types/ExecResult"; type Props = { status: ExecResultStatus; diff --git a/frontend/app/components/Gaming/SubmitResult.tsx b/frontend/app/components/Gaming/SubmitResult.tsx index 93e08a7..c626910 100644 --- a/frontend/app/components/Gaming/SubmitResult.tsx +++ b/frontend/app/components/Gaming/SubmitResult.tsx @@ -1,5 +1,5 @@ import React from "react"; -import type { SubmitResult } from "../../models/SubmitResult"; +import type { SubmitResult } from "../../types/SubmitResult"; import BorderedContainer from "../BorderedContainer"; import SubmitStatusLabel from "../SubmitStatusLabel"; import ExecStatusIndicatorIcon from "./ExecStatusIndicatorIcon"; diff --git a/frontend/app/components/GolfPlayApp.client.tsx b/frontend/app/components/GolfPlayApp.client.tsx index 42f0250..80cfc40 100644 --- a/frontend/app/components/GolfPlayApp.client.tsx +++ b/frontend/app/components/GolfPlayApp.client.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from "react"; import { useDebouncedCallback } from "use-debounce"; import type { components } from "../.server/api/schema"; import useWebSocket, { ReadyState } from "../hooks/useWebSocket"; -import type { PlayerInfo } from "../models/PlayerInfo"; +import type { PlayerState } from "../types/PlayerState"; import GolfPlayAppConnecting from "./GolfPlayApps/GolfPlayAppConnecting"; import GolfPlayAppFinished from "./GolfPlayApps/GolfPlayAppFinished"; import GolfPlayAppGaming from "./GolfPlayApps/GolfPlayAppGaming"; @@ -72,9 +72,12 @@ export default function GolfPlayApp({ } }, [gameState, startedAt, game.duration_seconds]); - const [playerInfo, setPlayerInfo] = useState<Omit<PlayerInfo, "code">>({ + const playerProfile = { displayName: player.display_name, iconPath: player.icon_path ?? null, + }; + const [playerState, setPlayerState] = useState<PlayerState>({ + code: "", score: null, submitResult: { status: "waiting_submission", @@ -105,7 +108,7 @@ export default function GolfPlayApp({ type: "player:c2s:submit", data: { code }, }); - setPlayerInfo((prev) => ({ + setPlayerState((prev) => ({ ...prev, submitResult: { status: "running", @@ -147,7 +150,7 @@ export default function GolfPlayApp({ } } else if (lastJsonMessage.type === "player:s2c:execresult") { const { testcase_id, status, stdout, stderr } = lastJsonMessage.data; - setPlayerInfo((prev) => { + setPlayerState((prev) => { const ret = { ...prev }; ret.submitResult = { ...prev.submitResult, @@ -166,7 +169,7 @@ export default function GolfPlayApp({ }); } else if (lastJsonMessage.type === "player:s2c:submitresult") { const { status, score } = lastJsonMessage.data; - setPlayerInfo((prev) => { + setPlayerState((prev) => { const ret = { ...prev }; ret.submitResult = { ...prev.submitResult, @@ -228,7 +231,7 @@ export default function GolfPlayApp({ return ( <GolfPlayAppWaiting gameDisplayName={game.display_name} - playerInfo={playerInfo} + playerProfile={playerProfile} /> ); } else if (gameState === "starting") { @@ -244,7 +247,10 @@ export default function GolfPlayApp({ gameDisplayName={game.display_name} gameDurationSeconds={game.duration_seconds} leftTimeSeconds={leftTimeSeconds!} - playerInfo={playerInfo} + playerInfo={{ + profile: playerProfile, + state: playerState, + }} problemTitle={game.problem.title} problemDescription={game.problem.description} onCodeChange={onCodeChange} diff --git a/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx b/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx index e6cb7e9..38516bc 100644 --- a/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx +++ b/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx @@ -1,7 +1,7 @@ import { Link } from "@remix-run/react"; import React, { useRef } from "react"; import SubmitButton from "../../components/SubmitButton"; -import type { PlayerInfo } from "../../models/PlayerInfo"; +import type { PlayerInfo } from "../../types/PlayerInfo"; import BorderedContainer from "../BorderedContainer"; import SubmitResult from "../Gaming/SubmitResult"; import UserIcon from "../UserIcon"; @@ -10,7 +10,7 @@ type Props = { gameDisplayName: string; gameDurationSeconds: number; leftTimeSeconds: number; - playerInfo: Omit<PlayerInfo, "code">; + playerInfo: PlayerInfo; problemTitle: string; problemDescription: string; onCodeChange: (code: string) => void; @@ -55,15 +55,15 @@ export default function GolfPlayAppGaming({ </div> <Link to={"/dashboard"}> <div className="flex gap-4 my-auto font-bold"> - <div className="text-6xl">{playerInfo.score}</div> + <div className="text-6xl">{playerInfo.state.score}</div> <div className="text-end"> <div className="text-gray-100">Player 1</div> - <div className="text-2xl">{playerInfo.displayName}</div> + <div className="text-2xl">{playerInfo.profile.displayName}</div> </div> - {playerInfo.iconPath && ( + {playerInfo.profile.iconPath && ( <UserIcon - iconPath={playerInfo.iconPath} - displayName={playerInfo.displayName!} + iconPath={playerInfo.profile.iconPath} + displayName={playerInfo.profile.displayName} className="w-12 h-12 my-auto" /> )} @@ -88,7 +88,7 @@ export default function GolfPlayAppGaming({ </div> <div className="p-4"> <SubmitResult - result={playerInfo.submitResult} + result={playerInfo.state.submitResult} submitButton={ <SubmitButton onClick={handleSubmitButtonClick}> 提出 diff --git a/frontend/app/components/GolfPlayApps/GolfPlayAppWaiting.tsx b/frontend/app/components/GolfPlayApps/GolfPlayAppWaiting.tsx index a31e5f4..706dc8f 100644 --- a/frontend/app/components/GolfPlayApps/GolfPlayAppWaiting.tsx +++ b/frontend/app/components/GolfPlayApps/GolfPlayAppWaiting.tsx @@ -1,14 +1,14 @@ -import { PlayerInfo } from "../../models/PlayerInfo"; -import PlayerProfile from "../PlayerProfile"; +import type { PlayerProfile } from "../../types/PlayerProfile"; +import PlayerNameAndIcon from "../PlayerNameAndIcon"; type Props = { gameDisplayName: string; - playerInfo: Omit<PlayerInfo, "code">; + playerProfile: PlayerProfile; }; export default function GolfPlayAppWaiting({ gameDisplayName, - playerInfo, + playerProfile, }: Props) { return ( <div className="min-h-screen bg-gray-100 flex flex-col font-bold text-center"> @@ -16,7 +16,7 @@ export default function GolfPlayAppWaiting({ <div className="text-4xl">{gameDisplayName}</div> </div> <div className="grow grid mx-auto text-black"> - <PlayerProfile playerInfo={playerInfo} label="You" /> + <PlayerNameAndIcon label="You" profile={playerProfile} /> </div> </div> ); diff --git a/frontend/app/components/GolfWatchApp.client.tsx b/frontend/app/components/GolfWatchApp.client.tsx index d09a4ae..9eacb2d 100644 --- a/frontend/app/components/GolfWatchApp.client.tsx +++ b/frontend/app/components/GolfWatchApp.client.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from "react"; import { AudioController } from "../.client/audio/AudioController"; import type { components } from "../.server/api/schema"; import useWebSocket, { ReadyState } from "../hooks/useWebSocket"; -import type { PlayerInfo } from "../models/PlayerInfo"; +import type { PlayerState } from "../types/PlayerState"; import GolfWatchAppConnecting from "./GolfWatchApps/GolfWatchAppConnecting"; import GolfWatchAppGaming from "./GolfWatchApps/GolfWatchAppGaming"; import GolfWatchAppStarting from "./GolfWatchApps/GolfWatchAppStarting"; @@ -73,12 +73,14 @@ export default function GolfWatchApp({ } }, [gameState, startedAt, game.duration_seconds, audioController]); - const playerA = game.players[0]; - const playerB = game.players[1]; + const playerA = game.players[0]!; + const playerB = game.players[1]!; - const [playerInfoA, setPlayerInfoA] = useState<PlayerInfo>({ - displayName: playerA?.display_name ?? null, - iconPath: playerA?.icon_path ?? null, + const playerProfileA = { + displayName: playerA.display_name, + iconPath: playerA.icon_path ?? null, + }; + const [playerStateA, setPlayerStateA] = useState<PlayerState>({ score: null, code: "", submitResult: { @@ -92,9 +94,11 @@ export default function GolfWatchApp({ })), }, }); - const [playerInfoB, setPlayerInfoB] = useState<PlayerInfo>({ - displayName: playerB?.display_name ?? null, - iconPath: playerB?.icon_path ?? null, + const playerProfileB = { + displayName: playerB.display_name, + iconPath: playerB.icon_path ?? null, + }; + const [playerStateB, setPlayerStateB] = useState<PlayerState>({ score: null, code: "", submitResult: { @@ -138,12 +142,12 @@ export default function GolfWatchApp({ } else if (lastJsonMessage.type === "watcher:s2c:code") { const { player_id, code } = lastJsonMessage.data; const setter = - player_id === playerA?.user_id ? setPlayerInfoA : setPlayerInfoB; + player_id === playerA.user_id ? setPlayerStateA : setPlayerStateB; setter((prev) => ({ ...prev, code })); } else if (lastJsonMessage.type === "watcher:s2c:submit") { const { player_id } = lastJsonMessage.data; const setter = - player_id === playerA?.user_id ? setPlayerInfoA : setPlayerInfoB; + player_id === playerA.user_id ? setPlayerStateA : setPlayerStateB; setter((prev) => ({ ...prev, submitResult: { @@ -160,7 +164,7 @@ export default function GolfWatchApp({ const { player_id, testcase_id, status, stdout, stderr } = lastJsonMessage.data; const setter = - player_id === playerA?.user_id ? setPlayerInfoA : setPlayerInfoB; + player_id === playerA.user_id ? setPlayerStateA : setPlayerStateB; setter((prev) => { const ret = { ...prev }; ret.submitResult = { @@ -181,7 +185,7 @@ export default function GolfWatchApp({ } else if (lastJsonMessage.type === "watcher:s2c:submitresult") { const { player_id, status, score } = lastJsonMessage.data; const setter = - player_id === playerA?.user_id ? setPlayerInfoA : setPlayerInfoB; + player_id === playerA.user_id ? setPlayerStateA : setPlayerStateB; setter((prev) => { const ret = { ...prev }; ret.submitResult = { @@ -235,8 +239,8 @@ export default function GolfWatchApp({ lastJsonMessage, readyState, gameState, - playerA?.user_id, - playerB?.user_id, + playerA.user_id, + playerB.user_id, ]); if (gameState === "connecting") { @@ -245,8 +249,8 @@ export default function GolfWatchApp({ return ( <GolfWatchAppWaiting gameDisplayName={game.display_name} - playerInfoA={playerInfoA} - playerInfoB={playerInfoB} + playerProfileA={playerProfileA} + playerProfileB={playerProfileB} /> ); } else if (gameState === "starting") { @@ -262,8 +266,14 @@ export default function GolfWatchApp({ gameDisplayName={game.display_name} gameDurationSeconds={game.duration_seconds} leftTimeSeconds={leftTimeSeconds!} - playerInfoA={playerInfoA} - playerInfoB={playerInfoB} + playerInfoA={{ + profile: playerProfileA, + state: playerStateA, + }} + playerInfoB={{ + profile: playerProfileB, + state: playerStateB, + }} problemTitle={game.problem.title} problemDescription={game.problem.description} gameResult={null /* TODO */} diff --git a/frontend/app/components/GolfWatchApps/GolfWatchAppGaming.tsx b/frontend/app/components/GolfWatchApps/GolfWatchAppGaming.tsx index 28babff..a23a972 100644 --- a/frontend/app/components/GolfWatchApps/GolfWatchAppGaming.tsx +++ b/frontend/app/components/GolfWatchApps/GolfWatchAppGaming.tsx @@ -1,4 +1,4 @@ -import { PlayerInfo } from "../../models/PlayerInfo"; +import type { PlayerInfo } from "../../types/PlayerInfo"; import BorderedContainer from "../BorderedContainer"; import CodeBlock from "../Gaming/CodeBlock"; import ScoreBar from "../Gaming/ScoreBar"; @@ -49,43 +49,43 @@ export default function GolfWatchAppGaming({ <div className={`text-white ${topBg} grid grid-cols-3 px-4 py-2`}> <div className="font-bold flex justify-between my-auto"> <div className="flex gap-6"> - {playerInfoA.iconPath && ( + {playerInfoA.profile.iconPath && ( <UserIcon - iconPath={playerInfoA.iconPath} - displayName={playerInfoA.displayName!} + iconPath={playerInfoA.profile.iconPath} + displayName={playerInfoA.profile.displayName} className="w-12 h-12 my-auto" /> )} <div> <div className="text-gray-100">Player 1</div> - <div className="text-2xl">{playerInfoA.displayName}</div> + <div className="text-2xl">{playerInfoA.profile.displayName}</div> </div> </div> - <div className="text-6xl">{playerInfoA.score}</div> + <div className="text-6xl">{playerInfoA.state.score}</div> </div> <div className="font-bold text-center"> <div className="text-gray-100">{gameDisplayName}</div> <div className="text-3xl"> {gameResult ? gameResult === "winA" - ? `勝者 ${playerInfoA.displayName}` + ? `勝者 ${playerInfoA.profile.displayName}` : gameResult === "winB" - ? `勝者 ${playerInfoB.displayName}` + ? `勝者 ${playerInfoB.profile.displayName}` : "引き分け" : leftTime} </div> </div> <div className="font-bold flex justify-between my-auto"> - <div className="text-6xl">{playerInfoB.score}</div> + <div className="text-6xl">{playerInfoB.state.score}</div> <div className="flex gap-6 text-end"> <div> <div className="text-gray-100">Player 2</div> - <div className="text-2xl">{playerInfoB.displayName}</div> + <div className="text-2xl">{playerInfoB.profile.displayName}</div> </div> - {playerInfoB.iconPath && ( + {playerInfoB.profile.iconPath && ( <UserIcon - iconPath={playerInfoB.iconPath} - displayName={playerInfoB.displayName!} + iconPath={playerInfoB.profile.iconPath} + displayName={playerInfoB.profile.displayName} className="w-12 h-12 my-auto" /> )} @@ -93,17 +93,17 @@ export default function GolfWatchAppGaming({ </div> </div> <ScoreBar - scoreA={playerInfoA.score} - scoreB={playerInfoB.score} + scoreA={playerInfoA.state.score} + scoreB={playerInfoB.state.score} bgA="bg-orange-400" bgB="bg-purple-400" /> <div className="grow grid grid-cols-3 p-4 gap-4"> - <CodeBlock code={playerInfoA.code ?? ""} language="swift" /> + <CodeBlock code={playerInfoA.state.code ?? ""} language="swift" /> <div className="flex flex-col gap-4"> <div className="grid grid-cols-2 gap-4"> - <SubmitResult result={playerInfoA.submitResult} /> - <SubmitResult result={playerInfoB.submitResult} /> + <SubmitResult result={playerInfoA.state.submitResult} /> + <SubmitResult result={playerInfoB.state.submitResult} /> </div> <div> <div className="mb-2 text-center text-xl font-bold"> @@ -112,7 +112,7 @@ export default function GolfWatchAppGaming({ <BorderedContainer>{problemDescription}</BorderedContainer> </div> </div> - <CodeBlock code={playerInfoB.code ?? ""} language="swift" /> + <CodeBlock code={playerInfoB.state.code ?? ""} language="swift" /> </div> </div> ); diff --git a/frontend/app/components/GolfWatchApps/GolfWatchAppWaiting.tsx b/frontend/app/components/GolfWatchApps/GolfWatchAppWaiting.tsx index faa9485..0e964e3 100644 --- a/frontend/app/components/GolfWatchApps/GolfWatchAppWaiting.tsx +++ b/frontend/app/components/GolfWatchApps/GolfWatchAppWaiting.tsx @@ -1,18 +1,16 @@ -import { PlayerInfo as FullPlayerInfo } from "../../models/PlayerInfo"; -import PlayerProfile from "../PlayerProfile"; - -type PlayerInfo = Pick<FullPlayerInfo, "displayName" | "iconPath">; +import type { PlayerProfile } from "../../types/PlayerProfile"; +import PlayerNameAndIcon from "../PlayerNameAndIcon"; type Props = { gameDisplayName: string; - playerInfoA: PlayerInfo; - playerInfoB: PlayerInfo; + playerProfileA: PlayerProfile; + playerProfileB: PlayerProfile; }; export default function GolfWatchAppWaiting({ gameDisplayName, - playerInfoA, - playerInfoB, + playerProfileA, + playerProfileB, }: Props) { return ( <div className="min-h-screen bg-gray-100 flex flex-col font-bold text-center"> @@ -20,9 +18,9 @@ export default function GolfWatchAppWaiting({ <div className="text-4xl">{gameDisplayName}</div> </div> <div className="grow grid grid-cols-3 gap-10 mx-auto text-black"> - <PlayerProfile playerInfo={playerInfoA} label="Player 1" /> + <PlayerNameAndIcon label="Player 1" profile={playerProfileA} /> <div className="text-8xl my-auto">vs.</div> - <PlayerProfile playerInfo={playerInfoB} label="Player 2" /> + <PlayerNameAndIcon label="Player 2" profile={playerProfileB} /> </div> </div> ); diff --git a/frontend/app/components/PlayerNameAndIcon.tsx b/frontend/app/components/PlayerNameAndIcon.tsx new file mode 100644 index 0000000..e9536e3 --- /dev/null +++ b/frontend/app/components/PlayerNameAndIcon.tsx @@ -0,0 +1,25 @@ +import { PlayerProfile } from "../types/PlayerProfile"; +import UserIcon from "./UserIcon"; + +type Props = { + label: string; + profile: PlayerProfile; +}; + +export default function PlayerNameAndIcon({ label, profile }: Props) { + return ( + <div className="flex flex-col gap-6 my-auto"> + <div className="flex flex-col gap-2"> + <div className="text-4xl">{label}</div> + <div className="text-6xl">{profile.displayName}</div> + </div> + {profile.iconPath && ( + <UserIcon + iconPath={profile.iconPath} + displayName={profile.displayName} + className="w-48 h-48" + /> + )} + </div> + ); +} diff --git a/frontend/app/components/PlayerProfile.tsx b/frontend/app/components/PlayerProfile.tsx deleted file mode 100644 index 675d77b..0000000 --- a/frontend/app/components/PlayerProfile.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import { PlayerInfo as FullPlayerInfo } from "../models/PlayerInfo"; -import UserIcon from "./UserIcon"; - -type PlayerInfo = Pick<FullPlayerInfo, "displayName" | "iconPath">; - -type Props = { - playerInfo: PlayerInfo; - label: string; -}; - -export default function PlayerProfile({ playerInfo, label }: Props) { - return ( - <div className="flex flex-col gap-6 my-auto"> - <div className="flex flex-col gap-2"> - <div className="text-4xl">{label}</div> - <div className="text-6xl">{playerInfo.displayName}</div> - </div> - {playerInfo.iconPath && ( - <UserIcon - iconPath={playerInfo.iconPath} - displayName={playerInfo.displayName!} - className="w-48 h-48" - /> - )} - </div> - ); -} diff --git a/frontend/app/components/SubmitStatusLabel.tsx b/frontend/app/components/SubmitStatusLabel.tsx index 0e13c1e..d1dc89c 100644 --- a/frontend/app/components/SubmitStatusLabel.tsx +++ b/frontend/app/components/SubmitStatusLabel.tsx @@ -1,4 +1,4 @@ -import type { SubmitResultStatus } from "../models/SubmitResult"; +import type { SubmitResultStatus } from "../types/SubmitResult"; type Props = { status: SubmitResultStatus; diff --git a/frontend/app/models/ExecResult.ts b/frontend/app/types/ExecResult.ts index e0b6bb4..e0b6bb4 100644 --- a/frontend/app/models/ExecResult.ts +++ b/frontend/app/types/ExecResult.ts diff --git a/frontend/app/types/PlayerInfo.ts b/frontend/app/types/PlayerInfo.ts new file mode 100644 index 0000000..e282ba9 --- /dev/null +++ b/frontend/app/types/PlayerInfo.ts @@ -0,0 +1,7 @@ +import type { PlayerProfile } from "./PlayerProfile"; +import type { PlayerState } from "./PlayerState"; + +export type PlayerInfo = { + profile: PlayerProfile; + state: PlayerState; +}; diff --git a/frontend/app/types/PlayerProfile.ts b/frontend/app/types/PlayerProfile.ts new file mode 100644 index 0000000..42bdcb8 --- /dev/null +++ b/frontend/app/types/PlayerProfile.ts @@ -0,0 +1,4 @@ +export type PlayerProfile = { + displayName: string; + iconPath: string | null; +}; diff --git a/frontend/app/models/PlayerInfo.ts b/frontend/app/types/PlayerState.ts index 8092ab3..e2a2da9 100644 --- a/frontend/app/models/PlayerInfo.ts +++ b/frontend/app/types/PlayerState.ts @@ -1,9 +1,7 @@ import type { SubmitResult } from "./SubmitResult"; -export type PlayerInfo = { - displayName: string | null; - iconPath: string | null; +export type PlayerState = { score: number | null; - code: string | null; + code: string; submitResult: SubmitResult; }; diff --git a/frontend/app/models/SubmitResult.ts b/frontend/app/types/SubmitResult.ts index 6df00b6..6df00b6 100644 --- a/frontend/app/models/SubmitResult.ts +++ b/frontend/app/types/SubmitResult.ts |
