From 17c1fbe0f8565f191a191138bebac7409512962e Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 15 Mar 2025 23:23:16 +0900 Subject: feat(frontend): improve left time display --- frontend/app/components/Gaming/LeftTime.tsx | 26 ++++++++++++++++++++++ .../components/GolfPlayApps/GolfPlayAppGaming.tsx | 9 ++------ .../GolfWatchApps/GolfWatchAppGaming1v1.tsx | 21 ++++++++--------- .../GolfWatchAppGamingMultiplayer.tsx | 9 ++------ 4 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 frontend/app/components/Gaming/LeftTime.tsx (limited to 'frontend') diff --git a/frontend/app/components/Gaming/LeftTime.tsx b/frontend/app/components/Gaming/LeftTime.tsx new file mode 100644 index 0000000..a31c6b2 --- /dev/null +++ b/frontend/app/components/Gaming/LeftTime.tsx @@ -0,0 +1,26 @@ +type Props = { + sec: number; +}; + +export default function LeftTime({ sec }: Props) { + const s = sec % 60; + const m = Math.floor(sec / 60) % 60; + const h = Math.floor(sec / 3600) % 24; + const d = Math.floor(sec / 86400); + + let leftTime = ""; + if (d > 0 || h > 0) { + // 1d 2h 3m 4s + leftTime = [ + d > 0 ? `${d}d` : "", + h > 0 ? `${h}h` : "", + m > 0 ? `${m}m` : "", + `${s}s`, + ].join(" "); + } else { + // 03:04 + leftTime = `${m.toString().padStart(2, "0")}:${s.toString().padStart(2, "0")}`; + } + + return
{leftTime}
; +} diff --git a/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx b/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx index 5c5e149..743588d 100644 --- a/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx +++ b/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx @@ -8,6 +8,7 @@ import { statusAtom, } from "../../states/play"; import type { PlayerProfile } from "../../types/PlayerProfile"; +import LeftTime from "../Gaming/LeftTime"; import Problem from "../Gaming/Problem"; import SubmitResult from "../Gaming/SubmitResult"; import UserIcon from "../UserIcon"; @@ -49,18 +50,12 @@ export default function GolfPlayAppGaming({ } }; - const leftTime = (() => { - const m = Math.floor(leftTimeSeconds / 60); - const s = leftTimeSeconds % 60; - return `${m.toString().padStart(2, "0")}:${s.toString().padStart(2, "0")}`; - })(); - return (
{gameDisplayName}
-
{leftTime}
+
diff --git a/frontend/app/components/GolfWatchApps/GolfWatchAppGaming1v1.tsx b/frontend/app/components/GolfWatchApps/GolfWatchAppGaming1v1.tsx index d9ee800..8e2b565 100644 --- a/frontend/app/components/GolfWatchApps/GolfWatchAppGaming1v1.tsx +++ b/frontend/app/components/GolfWatchApps/GolfWatchAppGaming1v1.tsx @@ -5,6 +5,7 @@ import { } from "../../states/watch"; import type { PlayerProfile } from "../../types/PlayerProfile"; import CodeBlock from "../Gaming/CodeBlock"; +import LeftTime from "../Gaming/LeftTime"; import Problem from "../Gaming/Problem"; import ScoreBar from "../Gaming/ScoreBar"; import SubmitResult from "../Gaming/SubmitResult"; @@ -41,12 +42,6 @@ export default function GolfWatchAppGaming1v1({ const scoreB = stateB?.score ?? null; const statusB = stateB?.status ?? "none"; - const leftTime = (() => { - const m = Math.floor(leftTimeSeconds / 60); - const s = leftTimeSeconds % 60; - return `${m.toString().padStart(2, "0")}:${s.toString().padStart(2, "0")}`; - })(); - const topBg = gameResult ? gameResult === "winA" ? "bg-orange-400" @@ -76,15 +71,17 @@ export default function GolfWatchAppGaming1v1({
{gameDisplayName}
-
- {gameResult - ? gameResult === "winA" + {gameResult ? ( +
+ {gameResult === "winA" ? `勝者 ${playerProfileA.displayName}` : gameResult === "winB" ? `勝者 ${playerProfileB.displayName}` - : "引き分け" - : leftTime} -
+ : "引き分け"} +
+ ) : ( + + )}
{scoreB}
diff --git a/frontend/app/components/GolfWatchApps/GolfWatchAppGamingMultiplayer.tsx b/frontend/app/components/GolfWatchApps/GolfWatchAppGamingMultiplayer.tsx index ff60641..1b91620 100644 --- a/frontend/app/components/GolfWatchApps/GolfWatchAppGamingMultiplayer.tsx +++ b/frontend/app/components/GolfWatchApps/GolfWatchAppGamingMultiplayer.tsx @@ -1,6 +1,7 @@ import { useAtomValue } from "jotai"; import type { components } from "../../api/schema"; import { gamingLeftTimeSecondsAtom } from "../../states/watch"; +import LeftTime from "../Gaming/LeftTime"; import Problem from "../Gaming/Problem"; import UserLabel from "../UserLabel"; @@ -25,12 +26,6 @@ export default function GolfWatchAppGamingMultiplayer({ }: Props) { const leftTimeSeconds = useAtomValue(gamingLeftTimeSecondsAtom)!; - const leftTime = (() => { - const m = Math.floor(leftTimeSeconds / 60); - const s = leftTimeSeconds % 60; - return `${m.toString().padStart(2, "0")}:${s.toString().padStart(2, "0")}`; - })(); - const topBg = gameResult ? gameResult === "winA" ? "bg-orange-400" @@ -45,7 +40,7 @@ export default function GolfWatchAppGamingMultiplayer({
{gameDisplayName}
-
{leftTime}
+
-- cgit v1.2.3-70-g09d2