- Optional `estimatedReleaseDate` (date and time) on the minigames registry,
with a named migration and regenerated types.
- Sidebar: an `upcoming` game renders greyed out and non-interactive, with a
tooltip carrying the estimate and a live countdown. It is a hoverable row
rather than a disabled menu item, because a disabled Radix item sets
`pointer-events: none` and would swallow the tooltip.
- Page gate: each minigame page checks its registry status and renders
`MinigameComingSoon` instead of the arena while the game is upcoming, so a
typed URL cannot reach unfinished gameplay. The date is display only: the
game goes live when an admin flips `status` to active.
- Leaderboards exclude upcoming games, so they get neither a tab nor a board.
- Pure `countdown.ts` formatter plus a client ticker that computes the
remaining time only after mount, avoiding an SSR hydration mismatch.
Note: `registry.ts`, `payload-types.ts` and `migrations/index.ts` also carry
the Call for Fire registry row and its generated types. That feature was
committed as 6d6a5fb and announced a separate commit for those files; they are
included here because they are entangled with these edits in the same files.
Tests: pure countdown unit tests, registry/gate/leaderboard integration tests,
and an e2e that seeds an upcoming row, hovers the disabled sidebar entry to
assert the tooltip, and checks the coming-soon gate.
87 lines
3.4 KiB
TypeScript
87 lines
3.4 KiB
TypeScript
import type { Metadata } from "next";
|
|
import config from "@payload-config";
|
|
import { getPayload } from "payload";
|
|
import { headers as nextHeaders } from "next/headers";
|
|
import { redirect } from "next/navigation";
|
|
import { MinigameComingSoon } from "@/components/frontend/minigames/MinigameComingSoon";
|
|
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)",
|
|
description: "Intercept and type incoming radio traffic fast + accurately.",
|
|
};
|
|
|
|
export default async function RadioPage() {
|
|
const headers = await nextHeaders();
|
|
const payloadConfig = await config;
|
|
const payload = await getPayload({ config: payloadConfig });
|
|
const { user } = await payload.auth({ headers, canSetHeaders: false });
|
|
|
|
if (!user) {
|
|
redirect(`/login?returnTo=${encodeURIComponent("/minigames/radio")}`);
|
|
}
|
|
|
|
const release = await getMinigameReleaseState(payload, "radio");
|
|
if (release.upcoming && release.game) {
|
|
return <MinigameComingSoon game={release.game} />;
|
|
}
|
|
|
|
const profileRes = await payload.find({
|
|
collection: "profiles",
|
|
where: { user: { equals: user.id as number } },
|
|
limit: 1,
|
|
depth: 0,
|
|
overrideAccess: true,
|
|
select: {
|
|
progression: {
|
|
minigames: true,
|
|
},
|
|
},
|
|
});
|
|
|
|
const radioTraffic = profileRes.docs[0]?.progression?.minigames?.radioTraffic ?? {};
|
|
const stats = {
|
|
gamesPlayed: radioTraffic.gamesPlayed ?? 0,
|
|
totalMessages: radioTraffic.totalMessages ?? 0,
|
|
incorrectMessages: radioTraffic.incorrectMessages ?? 0,
|
|
bestScore: radioTraffic.bestScore ?? 0,
|
|
bestAccuracy: radioTraffic.bestAccuracy ?? 0,
|
|
bestSprintTimeMs: radioTraffic.bestSprintTimeMs ?? 0,
|
|
sprintGamesPlayed: radioTraffic.sprintGamesPlayed ?? 0,
|
|
sprintTotalMessages: radioTraffic.sprintTotalMessages ?? 0,
|
|
sprintIncorrectMessages: radioTraffic.sprintIncorrectMessages ?? 0,
|
|
sprintBestScore: radioTraffic.sprintBestScore ?? 0,
|
|
sprintBestAccuracy: radioTraffic.sprintBestAccuracy ?? 0,
|
|
watchGamesPlayed: radioTraffic.watchGamesPlayed ?? 0,
|
|
watchTotalMessages: radioTraffic.watchTotalMessages ?? 0,
|
|
watchIncorrectMessages: radioTraffic.watchIncorrectMessages ?? 0,
|
|
watchBestScore: radioTraffic.watchBestScore ?? 0,
|
|
watchBestAccuracy: radioTraffic.watchBestAccuracy ?? 0,
|
|
radioTrafficXp: radioTraffic.xpEarned ?? 0,
|
|
xpEarned: 0,
|
|
};
|
|
|
|
return (
|
|
<div className="flex min-w-0 flex-col gap-6 p-5">
|
|
<div className="flex flex-col gap-1">
|
|
<div className="flex items-center gap-2">
|
|
<Radio className="size-5 text-muted-foreground" />
|
|
<h1 className="text-lg font-semibold">Radio Traffic</h1>
|
|
</div>
|
|
<p className="text-sm text-muted-foreground">
|
|
Intercept and type incoming radio traffic fast + accurately.
|
|
</p>
|
|
</div>
|
|
|
|
<RadioArena initialStats={stats} currentUserId={user.id as number} />
|
|
|
|
<div className="flex flex-col gap-2">
|
|
<h2 className="text-sm font-semibold text-muted-foreground">Anchored period standings</h2>
|
|
<PeriodStandingsCard gameKey="radio" icon="Radio" currentUserId={user.id as number} />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|