diff --git a/src/app/(frontend)/minigames/call-for-fire/page.tsx b/src/app/(frontend)/minigames/call-for-fire/page.tsx index 56f1977e..918a8828 100644 --- a/src/app/(frontend)/minigames/call-for-fire/page.tsx +++ b/src/app/(frontend)/minigames/call-for-fire/page.tsx @@ -5,7 +5,6 @@ import { headers as nextHeaders } from "next/headers"; import { redirect } from "next/navigation"; import { Target } from "lucide-react"; import { CallForFireArena } from "@/components/frontend/minigames/call-for-fire/CallForFireArena"; -import { PeriodStandingsCard } from "@/components/frontend/minigames/PeriodStandingsCard"; import { PhasingOutBanner } from "@/components/frontend/minigames/PhasingOutBanner"; import { getMinigameReleaseState } from "@/lib/minigames/loadRegistry"; @@ -68,15 +67,6 @@ export default async function CallForFirePage() { - -
-

Anchored period standings

- -
); } diff --git a/src/app/(frontend)/minigames/eod/page.tsx b/src/app/(frontend)/minigames/eod/page.tsx index 0fdf6597..2afb02ac 100644 --- a/src/app/(frontend)/minigames/eod/page.tsx +++ b/src/app/(frontend)/minigames/eod/page.tsx @@ -8,7 +8,6 @@ import { PhasingOutBanner } from "@/components/frontend/minigames/PhasingOutBann import { getMinigameReleaseState } from "@/lib/minigames/loadRegistry"; import { Bomb } from "lucide-react"; import { EodArena } from "@/components/frontend/minigames/eod/EodArena"; -import { PeriodStandingsCard } from "@/components/frontend/minigames/PeriodStandingsCard"; export const metadata: Metadata = { title: "Minefield Clearance (Polaris Task Force)", @@ -72,11 +71,6 @@ export default async function EodPage() { - -
-

Anchored period standings

- -
); } diff --git a/src/app/(frontend)/minigames/flappy/page.tsx b/src/app/(frontend)/minigames/flappy/page.tsx index 88093f24..510c4ccd 100644 --- a/src/app/(frontend)/minigames/flappy/page.tsx +++ b/src/app/(frontend)/minigames/flappy/page.tsx @@ -8,7 +8,6 @@ import { PhasingOutBanner } from "@/components/frontend/minigames/PhasingOutBann import { getMinigameReleaseState } from "@/lib/minigames/loadRegistry"; import { Bird } from "lucide-react"; import { FlappyArena } from "@/components/frontend/minigames/flappy/FlappyArena"; -import { PeriodStandingsCard } from "@/components/frontend/minigames/PeriodStandingsCard"; export const metadata: Metadata = { title: "Flight Simulator: Polaris Task Force", @@ -70,11 +69,6 @@ export default async function FlappyPage() { - -
-

Anchored period standings

- -
); } diff --git a/src/app/(frontend)/minigames/opord/page.tsx b/src/app/(frontend)/minigames/opord/page.tsx index 007454a0..71071c59 100644 --- a/src/app/(frontend)/minigames/opord/page.tsx +++ b/src/app/(frontend)/minigames/opord/page.tsx @@ -8,7 +8,6 @@ import { PhasingOutBanner } from "@/components/frontend/minigames/PhasingOutBann import { getMinigameReleaseState } from "@/lib/minigames/loadRegistry"; import { ScrollText } from "lucide-react"; import { OpordArena } from "@/components/frontend/minigames/opord/OpordArena"; -import { PeriodStandingsCard } from "@/components/frontend/minigames/PeriodStandingsCard"; export const metadata: Metadata = { title: "OPORD Recall (Polaris Task Force)", @@ -73,11 +72,6 @@ export default async function OpordPage() { - -
-

Anchored period standings

- -
); } diff --git a/src/app/(frontend)/minigames/qualification/page.tsx b/src/app/(frontend)/minigames/qualification/page.tsx index 44cda45d..95d79d6a 100644 --- a/src/app/(frontend)/minigames/qualification/page.tsx +++ b/src/app/(frontend)/minigames/qualification/page.tsx @@ -10,7 +10,6 @@ import { Crosshair } from "lucide-react"; import type { AimTrainerStats } from "@/app/(frontend)/minigames/qualification/actions"; import { AimTrainerArena } from "@/components/frontend/minigames/qualification/AimTrainerArena"; -import { PeriodStandingsCard } from "@/components/frontend/minigames/PeriodStandingsCard"; export const metadata: Metadata = { title: "Qualification Course: Polaris Task Force", @@ -77,11 +76,6 @@ export default async function QualificationPage() { - -
-

Anchored period standings

- -
); } diff --git a/src/app/(frontend)/minigames/radio/page.tsx b/src/app/(frontend)/minigames/radio/page.tsx index 20869518..38079f3b 100644 --- a/src/app/(frontend)/minigames/radio/page.tsx +++ b/src/app/(frontend)/minigames/radio/page.tsx @@ -8,7 +8,6 @@ import { PhasingOutBanner } from "@/components/frontend/minigames/PhasingOutBann import { getMinigameReleaseState } from "@/lib/minigames/loadRegistry"; import { Radio } from "lucide-react"; import { RadioArena } from "@/components/frontend/minigames/radio/RadioArena"; -import { PeriodStandingsCard } from "@/components/frontend/minigames/PeriodStandingsCard"; export const metadata: Metadata = { title: "Radio Traffic (Polaris Task Force)", @@ -81,11 +80,6 @@ export default async function RadioPage() { - -
-

Anchored period standings

- -
); } diff --git a/src/components/frontend/minigames/AllTimeLeaderboard.tsx b/src/components/frontend/minigames/AllTimeLeaderboard.tsx new file mode 100644 index 00000000..12e8d6fb --- /dev/null +++ b/src/components/frontend/minigames/AllTimeLeaderboard.tsx @@ -0,0 +1,40 @@ +"use client"; + +import { ChevronDown, History } from "lucide-react"; + +import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"; +import { cn } from "@/lib/utils"; + +export interface AllTimeLeaderboardProps { + children: React.ReactNode; + className?: string; +} + +/** + * Collapsed container for a game's lifetime board. The period standings stay + * the primary surface on the game page; the all-time board is opt-in. + */ +export function AllTimeLeaderboard({ children, className }: AllTimeLeaderboardProps) { + return ( + + + + + {children} + + ); +} diff --git a/src/components/frontend/minigames/PeriodStandingsCard.tsx b/src/components/frontend/minigames/PeriodStandingsCard.tsx index 52a6ed77..f73e9396 100644 --- a/src/components/frontend/minigames/PeriodStandingsCard.tsx +++ b/src/components/frontend/minigames/PeriodStandingsCard.tsx @@ -1,6 +1,5 @@ "use client"; -import { useState } from "react"; import Link from "next/link"; import { Trophy } from "lucide-react"; @@ -22,9 +21,9 @@ export interface PeriodStandingsCardProps { } /** - * Period-scoped standings for a single game, embedded on the game page. Defaults - * to the current period and offers an All-Time toggle; the full multi-board view - * lives at /minigames/leaderboards. + * Current-period standings for a single game, embedded on the game page. The + * game's lifetime board sits below it in a collapsed all-time section; the full + * multi-board view lives at /minigames/leaderboards. */ export function PeriodStandingsCard({ gameKey, @@ -34,12 +33,13 @@ export function PeriodStandingsCard({ presence, className, }: PeriodStandingsCardProps) { - const [view, setView] = useState<"period" | "all-time">("period"); - const { data, failed, loading } = useLeaderboards(view === "all-time" ? "all-time" : "current", refreshKey); + const { data, failed, loading } = useLeaderboards("current", refreshKey); const board = data?.boards.find((entry) => entry.key === gameKey) ?? null; const Icon = minigameIcon(icon ?? board?.icon); - const isAllTime = view === "all-time"; + const presenceNoun = presence?.noun ?? "operator"; + const presenceLabel = + presence && presence.participants.length === 1 ? presenceNoun : `${presenceNoun}s`; return (
@@ -48,43 +48,27 @@ export function PeriodStandingsCard({

{board?.label ?? "Standings"}

- {isAllTime ? "All-Time" : (data?.period?.label ?? "No active period")} + {data?.period?.label ?? "No active period"}
-
- - +
+ Best run this period ยท placement points All boards
- {presence && !isAllTime && ( -
+ {presence && ( +
{presence.participants.length}{" "} - {presence.participants.length === 1 ? `${presence.noun ?? "operator"} is` : `${presence.noun ?? "operators"} are`} active now + {presenceLabel} {presence.participants.length === 1 ? "is" : "are"} active now {presence.participants.length > 0 && ( ({presence.participants.map((participant) => participant.name).join(", ")}) @@ -106,8 +90,8 @@ export function PeriodStandingsCard({ rows={board?.rows ?? []} scoreLabel={board?.scoreLabel ?? "Score"} currentUserId={currentUserId} - showPoints={!isAllTime} - emptyLabel={isAllTime ? "No all-time runs yet." : "No runs this period yet. Be the first!"} + showPoints + emptyLabel="No runs this period yet. Be the first!" /> )}
diff --git a/src/components/frontend/minigames/call-for-fire/CallForFireArena.tsx b/src/components/frontend/minigames/call-for-fire/CallForFireArena.tsx index 4f9f189e..c7bee7d9 100644 --- a/src/components/frontend/minigames/call-for-fire/CallForFireArena.tsx +++ b/src/components/frontend/minigames/call-for-fire/CallForFireArena.tsx @@ -7,6 +7,8 @@ import type { } from "@/app/(frontend)/minigames/call-for-fire/actions"; import { useRealtimePresence } from "@/hooks/useRealtimePresence"; import { useSidebar } from "@/components/ui/sidebar"; +import { AllTimeLeaderboard } from "@/components/frontend/minigames/AllTimeLeaderboard"; +import { PeriodStandingsCard } from "@/components/frontend/minigames/PeriodStandingsCard"; import { CallForFireLeaderboard } from "./CallForFireLeaderboard"; import { FireMissionBoard } from "./FireMissionBoard"; @@ -38,13 +40,23 @@ export function CallForFireArena({ onPhaseChange={onPhaseChange} onDifficultyChange={setSelectedDifficulty} /> - + + +
); } diff --git a/src/components/frontend/minigames/eod/EodArena.tsx b/src/components/frontend/minigames/eod/EodArena.tsx index be1a74cd..32eb25e8 100644 --- a/src/components/frontend/minigames/eod/EodArena.tsx +++ b/src/components/frontend/minigames/eod/EodArena.tsx @@ -5,6 +5,8 @@ import type { EodDifficulty, EodStats } from "@/app/(frontend)/minigames/eod/act import { isEodUnlocked } from "@/lib/minigames/custom/eod"; import { useRealtimePresence } from "@/hooks/useRealtimePresence"; import { useSidebar } from "@/components/ui/sidebar"; +import { AllTimeLeaderboard } from "@/components/frontend/minigames/AllTimeLeaderboard"; +import { PeriodStandingsCard } from "@/components/frontend/minigames/PeriodStandingsCard"; import { UnlockNotice } from "@/components/frontend/minigames/UnlockNotice"; import { UgcLinkButton } from "@/components/frontend/minigames/UgcLinkButton"; import { EodLeaderboard } from "./EodLeaderboard"; @@ -64,13 +66,23 @@ export function EodArena({ onPhaseChange={onPhaseChange} onDifficultyChange={setSelectedDifficulty} /> - + + +
); } diff --git a/src/components/frontend/minigames/flappy/FlappyArena.tsx b/src/components/frontend/minigames/flappy/FlappyArena.tsx index 23ea2538..15bbf2f9 100644 --- a/src/components/frontend/minigames/flappy/FlappyArena.tsx +++ b/src/components/frontend/minigames/flappy/FlappyArena.tsx @@ -3,6 +3,8 @@ import { useCallback, useState } from "react"; import type { FlappyStats } from "@/app/(frontend)/minigames/flappy/actions"; import { useRealtimePresence } from "@/hooks/useRealtimePresence"; +import { AllTimeLeaderboard } from "@/components/frontend/minigames/AllTimeLeaderboard"; +import { PeriodStandingsCard } from "@/components/frontend/minigames/PeriodStandingsCard"; import { FlappyBird } from "./FlappyBird"; import { FlappyLeaderboard } from "./FlappyLeaderboard"; @@ -24,7 +26,16 @@ export function FlappyArena({ return (
setRefreshKey((k) => k + 1)} onPhaseChange={onPhaseChange} /> - + + + +
); } diff --git a/src/components/frontend/minigames/opord/OpordArena.tsx b/src/components/frontend/minigames/opord/OpordArena.tsx index d153404c..45d16225 100644 --- a/src/components/frontend/minigames/opord/OpordArena.tsx +++ b/src/components/frontend/minigames/opord/OpordArena.tsx @@ -6,6 +6,8 @@ import { OPORD_DIFFICULTIES, type OpordDifficulty } from "@/lib/minigames/opord- import type { OpordStats } from "@/app/(frontend)/minigames/opord/actions"; import { useRealtimePresence } from "@/hooks/useRealtimePresence"; import { useSidebar } from "@/components/ui/sidebar"; +import { AllTimeLeaderboard } from "@/components/frontend/minigames/AllTimeLeaderboard"; +import { PeriodStandingsCard } from "@/components/frontend/minigames/PeriodStandingsCard"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { cn } from "@/lib/utils"; @@ -158,12 +160,22 @@ export function OpordArena({ - + + + ); } diff --git a/src/components/frontend/minigames/qualification/AimTrainerArena.tsx b/src/components/frontend/minigames/qualification/AimTrainerArena.tsx index a2001b70..8028e886 100644 --- a/src/components/frontend/minigames/qualification/AimTrainerArena.tsx +++ b/src/components/frontend/minigames/qualification/AimTrainerArena.tsx @@ -10,6 +10,8 @@ import { import type { AimTrainerStats } from "@/app/(frontend)/minigames/qualification/actions"; import { useRealtimePresence } from "@/hooks/useRealtimePresence"; import { useSidebar } from "@/components/ui/sidebar"; +import { AllTimeLeaderboard } from "@/components/frontend/minigames/AllTimeLeaderboard"; +import { PeriodStandingsCard } from "@/components/frontend/minigames/PeriodStandingsCard"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { cn } from "@/lib/utils"; @@ -170,12 +172,22 @@ export function AimTrainerArena({ - + + + ); } diff --git a/src/components/frontend/minigames/radio/RadioArena.tsx b/src/components/frontend/minigames/radio/RadioArena.tsx index 6152e1ee..ddb3153a 100644 --- a/src/components/frontend/minigames/radio/RadioArena.tsx +++ b/src/components/frontend/minigames/radio/RadioArena.tsx @@ -8,6 +8,8 @@ import { WATCH_ACCURACY_REQUIREMENT, } from "@/lib/minigames/custom/radio"; import { useRealtimePresence } from "@/hooks/useRealtimePresence"; +import { AllTimeLeaderboard } from "@/components/frontend/minigames/AllTimeLeaderboard"; +import { PeriodStandingsCard } from "@/components/frontend/minigames/PeriodStandingsCard"; import { UnlockNotice } from "@/components/frontend/minigames/UnlockNotice"; import { UgcLinkButton } from "@/components/frontend/minigames/UgcLinkButton"; import { RadioLeaderboard } from "./RadioLeaderboard"; @@ -90,13 +92,23 @@ export function RadioArena({
  • The lifetime leaderboard ranks Top Score, Top Accuracy, Fastest Sprint, and Most Messages.
  • - + + + ); } diff --git a/tests/e2e/minigame-leaderboards.e2e.spec.ts b/tests/e2e/minigame-leaderboards.e2e.spec.ts index e7e66297..57e86994 100644 --- a/tests/e2e/minigame-leaderboards.e2e.spec.ts +++ b/tests/e2e/minigame-leaderboards.e2e.spec.ts @@ -2,8 +2,8 @@ import { expect, test } from "@playwright/test"; /** * Smoke coverage for the unified minigames leaderboards: the period view, the - * All-Time switch (which also reveals the cardtable games) and the inline period - * standings card on a game page. + * All-Time switch (which also reveals the cardtable games) and the period + * standings card plus collapsed all-time board on a game page. */ test.describe("Minigame leaderboards", () => { test.beforeEach(async ({ page }) => { @@ -37,12 +37,21 @@ test.describe("Minigame leaderboards", () => { await expect(page.getByRole("tab", { name: "Blackjack" })).toBeVisible(); }); - test("a game page shows its anchored period standings card", async ({ page }) => { + test("a game page centers period standings with all-time collapsed", async ({ page }) => { await page.goto("/minigames/flappy"); - await expect( - page.getByRole("heading", { level: 2, name: "Anchored period standings" }), - ).toBeVisible(); await expect(page.getByRole("link", { name: "All boards" })).toBeVisible(); + + const allTime = page.getByRole("button", { name: /All-time leaderboard/ }); + await expect(allTime).toBeVisible(); + await expect(allTime).toHaveAttribute("data-state", "closed"); + await expect(page.getByText("Flight Simulator Leaderboard")).toHaveCount(0); + + // The dev-server first navigation can hydrate slowly, so retry the toggle + // until the collapsed board actually mounts. + await expect(async () => { + await allTime.click(); + await expect(page.getByText("Flight Simulator Leaderboard")).toBeVisible({ timeout: 1000 }); + }).toPass({ timeout: 20_000 }); }); });