From 80ee46c81dda5331f66aa401435447f22ff187cd Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 21 Mar 2025 09:23:01 +0900 Subject: feat(frontend): show game result in 1v1 watch --- .../GolfWatchApps/GolfWatchAppGaming1v1.tsx | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'frontend/app/components/GolfWatchApps/GolfWatchAppGaming1v1.tsx') diff --git a/frontend/app/components/GolfWatchApps/GolfWatchAppGaming1v1.tsx b/frontend/app/components/GolfWatchApps/GolfWatchAppGaming1v1.tsx index 63ad5f3..168f5d9 100644 --- a/frontend/app/components/GolfWatchApps/GolfWatchAppGaming1v1.tsx +++ b/frontend/app/components/GolfWatchApps/GolfWatchAppGaming1v1.tsx @@ -1,6 +1,8 @@ import { useAtomValue } from "jotai"; import { calcCodeSize, + checkGameResultKind, + gameStateKindAtom, gamingLeftTimeSecondsAtom, latestGameStatesAtom, } from "../../states/watch"; @@ -23,7 +25,6 @@ type Props = { problemTitle: string; problemDescription: string; sampleCode: string; - gameResult: "winA" | "winB" | "draw" | null; }; export default function GolfWatchAppGaming1v1({ @@ -33,16 +34,16 @@ export default function GolfWatchAppGaming1v1({ problemTitle, problemDescription, sampleCode, - gameResult, }: Props) { + const gameStateKind = useAtomValue(gameStateKindAtom); const leftTimeSeconds = useAtomValue(gamingLeftTimeSecondsAtom)!; const latestGameStates = useAtomValue(latestGameStatesAtom); - const stateA = latestGameStates[`${playerProfileA.id}`]; + const stateA = latestGameStates[`${playerProfileA.id}`] ?? null; const codeA = stateA?.code ?? ""; const scoreA = stateA?.score ?? null; const statusA = stateA?.status ?? "none"; - const stateB = latestGameStates[`${playerProfileB.id}`]; + const stateB = latestGameStates[`${playerProfileB.id}`] ?? null; const codeB = stateB?.code ?? ""; const scoreB = stateB?.score ?? null; const statusB = stateB?.status ?? "none"; @@ -50,10 +51,12 @@ export default function GolfWatchAppGaming1v1({ const codeSizeA = calcCodeSize(codeA); const codeSizeB = calcCodeSize(codeB); - const topBg = gameResult - ? gameResult === "winA" + const gameResultKind = checkGameResultKind(gameStateKind, stateA, stateB); + + const topBg = gameResultKind + ? gameResultKind === "winA" ? "bg-orange-400" - : gameResult === "winB" + : gameResultKind === "winB" ? "bg-purple-400" : "bg-sky-600" : "bg-sky-600"; @@ -76,11 +79,11 @@ export default function GolfWatchAppGaming1v1({
{gameDisplayName}
- {gameResult ? ( + {gameResultKind ? (
- {gameResult === "winA" + {gameResultKind === "winA" ? `勝者 ${playerProfileA.displayName}` - : gameResult === "winB" + : gameResultKind === "winB" ? `勝者 ${playerProfileB.displayName}` : "引き分け"}
-- cgit v1.2.3-70-g09d2