feat(minigames): show upcoming games as disabled with a release countdown
- 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.
This commit is contained in:
parent
6070cb670e
commit
0bb9719139
24 changed files with 40565 additions and 27 deletions
|
|
@ -3,6 +3,8 @@ 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 { Club } from "lucide-react";
|
||||
import { BlackjackArena } from "@/components/frontend/minigames/blackjack/BlackjackArena";
|
||||
import { readBlackjackStats } from "@/lib/minigames/blackjack/stats";
|
||||
|
|
@ -28,6 +30,11 @@ export default async function BlackjackPage({ searchParams }: BlackjackPageProps
|
|||
redirect(`/login?returnTo=${encodeURIComponent("/minigames/blackjack")}`);
|
||||
}
|
||||
|
||||
const release = await getMinigameReleaseState(payload, "blackjack");
|
||||
if (release.upcoming && release.game) {
|
||||
return <MinigameComingSoon game={release.game} />;
|
||||
}
|
||||
|
||||
const superuser = await isSuperuser(payload, user);
|
||||
const superuserIds = await superuserUserIds(payload);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ 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 { Bomb } from "lucide-react";
|
||||
import { EodArena } from "@/components/frontend/minigames/eod/EodArena";
|
||||
import { PeriodStandingsCard } from "@/components/frontend/minigames/PeriodStandingsCard";
|
||||
|
|
@ -22,6 +24,11 @@ export default async function EodPage() {
|
|||
redirect(`/login?returnTo=${encodeURIComponent("/minigames/eod")}`);
|
||||
}
|
||||
|
||||
const release = await getMinigameReleaseState(payload, "eod");
|
||||
if (release.upcoming && release.game) {
|
||||
return <MinigameComingSoon game={release.game} />;
|
||||
}
|
||||
|
||||
const profileRes = await payload.find({
|
||||
collection: "profiles",
|
||||
where: { user: { equals: user.id as number } },
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ 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 { Bird } from "lucide-react";
|
||||
import { FlappyArena } from "@/components/frontend/minigames/flappy/FlappyArena";
|
||||
import { PeriodStandingsCard } from "@/components/frontend/minigames/PeriodStandingsCard";
|
||||
|
|
@ -22,6 +24,11 @@ export default async function FlappyPage() {
|
|||
redirect(`/login?returnTo=${encodeURIComponent("/minigames/flappy")}`);
|
||||
}
|
||||
|
||||
const release = await getMinigameReleaseState(payload, "flappy");
|
||||
if (release.upcoming && release.game) {
|
||||
return <MinigameComingSoon game={release.game} />;
|
||||
}
|
||||
|
||||
const profileRes = await payload.find({
|
||||
collection: "profiles",
|
||||
where: { user: { equals: user.id as number } },
|
||||
|
|
|
|||
|
|
@ -28,10 +28,13 @@ export default async function MinigameLeaderboardsPage({
|
|||
}
|
||||
|
||||
const games = await loadMinigameRegistry(payload);
|
||||
// Upcoming games are excluded from the boards and tabs (they are disabled in
|
||||
// the sidebar), so they must not be the page's default selection either.
|
||||
const playableGames = games.filter((game) => game.status !== "upcoming");
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6 p-5">
|
||||
<MinigameLeaderboards games={games} currentUserId={user.id as number} initialGame={game} />
|
||||
<MinigameLeaderboards games={playableGames} currentUserId={user.id as number} initialGame={game} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ 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 { ScrollText } from "lucide-react";
|
||||
import { OpordArena } from "@/components/frontend/minigames/opord/OpordArena";
|
||||
import { PeriodStandingsCard } from "@/components/frontend/minigames/PeriodStandingsCard";
|
||||
|
|
@ -22,6 +24,11 @@ export default async function OpordPage() {
|
|||
redirect(`/login?returnTo=${encodeURIComponent("/minigames/opord")}`);
|
||||
}
|
||||
|
||||
const release = await getMinigameReleaseState(payload, "opord");
|
||||
if (release.upcoming && release.game) {
|
||||
return <MinigameComingSoon game={release.game} />;
|
||||
}
|
||||
|
||||
const profileRes = await payload.find({
|
||||
collection: "profiles",
|
||||
where: { user: { equals: user.id as number } },
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ 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 { Spade } from "lucide-react";
|
||||
import { PokerArena } from "@/components/frontend/minigames/poker/PokerArena";
|
||||
import { readPokerStats } from "@/lib/minigames/poker/stats";
|
||||
|
|
@ -28,6 +30,11 @@ export default async function PokerPage({ searchParams }: PokerPageProps) {
|
|||
redirect(`/login?returnTo=${encodeURIComponent("/minigames/poker")}`);
|
||||
}
|
||||
|
||||
const release = await getMinigameReleaseState(payload, "poker");
|
||||
if (release.upcoming && release.game) {
|
||||
return <MinigameComingSoon game={release.game} />;
|
||||
}
|
||||
|
||||
const superuser = await isSuperuser(payload, user);
|
||||
const superuserIds = await superuserUserIds(payload);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ 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 { Crosshair } from "lucide-react";
|
||||
|
||||
import type { AimTrainerStats } from "@/app/(frontend)/minigames/qualification/actions";
|
||||
|
|
@ -24,6 +26,11 @@ export default async function QualificationPage() {
|
|||
redirect(`/login?returnTo=${encodeURIComponent("/minigames/qualification")}`);
|
||||
}
|
||||
|
||||
const release = await getMinigameReleaseState(payload, "qualification");
|
||||
if (release.upcoming && release.game) {
|
||||
return <MinigameComingSoon game={release.game} />;
|
||||
}
|
||||
|
||||
const profileRes = await payload.find({
|
||||
collection: "profiles",
|
||||
where: { user: { equals: user.id as number } },
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ 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";
|
||||
|
|
@ -22,6 +24,11 @@ export default async function RadioPage() {
|
|||
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 } },
|
||||
|
|
|
|||
|
|
@ -73,6 +73,15 @@ export const Minigames: CollectionConfig = {
|
|||
{ label: "Retired", value: "retired" },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "estimatedReleaseDate",
|
||||
type: "date",
|
||||
admin: {
|
||||
date: { pickerAppearance: "dayAndTime" },
|
||||
description:
|
||||
"Optional target for an upcoming game. Shown as a countdown in the sidebar and on the game page. Display only: the game goes live when status changes to Active.",
|
||||
},
|
||||
},
|
||||
{ name: "order", type: "number", required: true, defaultValue: 0 },
|
||||
{
|
||||
name: "countsForPeriods",
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { ChevronRight, Gamepad2, Trophy } from "lucide-react";
|
|||
import Link from "next/link";
|
||||
|
||||
import { minigameIcon } from "@/components/frontend/minigames/minigameIcon";
|
||||
import { UpcomingCountdown } from "@/components/frontend/minigames/UpcomingCountdown";
|
||||
import type { RegistryGame } from "@/lib/minigames/registry";
|
||||
import {
|
||||
DropdownMenu,
|
||||
|
|
@ -19,11 +20,17 @@ import {
|
|||
SidebarMenuItem,
|
||||
useSidebar,
|
||||
} from "@/components/ui/sidebar";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
|
||||
/**
|
||||
* Minigames sidebar dropdown. The groups and entries come from the minigames
|
||||
* registry (resolved on the server and passed in), so retiring a game or
|
||||
* reordering the list is an admin-data change, not a code change.
|
||||
*
|
||||
* Retired games are hidden. `upcoming` games are shown greyed out and are not
|
||||
* links: they render as a plain hoverable row rather than a disabled
|
||||
* `DropdownMenuItem`, because that item sets `pointer-events: none` when
|
||||
* disabled, which would suppress the hover that reveals the tooltip.
|
||||
*/
|
||||
export function NavMinigames({ games }: { games: RegistryGame[] }) {
|
||||
const { isMobile } = useSidebar();
|
||||
|
|
@ -32,6 +39,41 @@ export function NavMinigames({ games }: { games: RegistryGame[] }) {
|
|||
const coreGames = visible.filter((game) => game.category === "core");
|
||||
const cardtableGames = visible.filter((game) => game.category === "cardtable");
|
||||
|
||||
const renderGame = (game: RegistryGame) => {
|
||||
const Icon = minigameIcon(game.icon);
|
||||
|
||||
if (game.status === "upcoming") {
|
||||
return (
|
||||
<Tooltip key={game.key}>
|
||||
<TooltipTrigger asChild>
|
||||
<div
|
||||
aria-disabled="true"
|
||||
className="relative flex w-full cursor-not-allowed select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm opacity-50 outline-none [&>svg]:size-4 [&>svg]:shrink-0"
|
||||
>
|
||||
<Icon />
|
||||
<span className="truncate">{game.label}</span>
|
||||
<span className="ml-auto shrink-0 text-[10px] font-normal uppercase tracking-wide">
|
||||
Upcoming
|
||||
</span>
|
||||
</div>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side={isMobile ? "bottom" : "right"}>
|
||||
<UpcomingCountdown estimatedReleaseDate={game.estimatedReleaseDate} variant="tooltip" />
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<DropdownMenuItem key={game.key} asChild>
|
||||
<Link href={game.route}>
|
||||
<Icon />
|
||||
{game.label}
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<SidebarMenuItem>
|
||||
<DropdownMenu>
|
||||
|
|
@ -50,17 +92,7 @@ export function NavMinigames({ games }: { games: RegistryGame[] }) {
|
|||
>
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuLabel>Core</DropdownMenuLabel>
|
||||
{coreGames.map((game) => {
|
||||
const Icon = minigameIcon(game.icon);
|
||||
return (
|
||||
<DropdownMenuItem key={game.key} asChild>
|
||||
<Link href={game.route}>
|
||||
<Icon />
|
||||
{game.label}
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
})}
|
||||
{coreGames.map(renderGame)}
|
||||
</DropdownMenuGroup>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuGroup>
|
||||
|
|
@ -68,17 +100,7 @@ export function NavMinigames({ games }: { games: RegistryGame[] }) {
|
|||
<span>Cardtable</span>
|
||||
<span className="text-xs font-normal text-muted-foreground">Earn chips to spend by playing Core minigames!</span>
|
||||
</DropdownMenuLabel>
|
||||
{cardtableGames.map((game) => {
|
||||
const Icon = minigameIcon(game.icon);
|
||||
return (
|
||||
<DropdownMenuItem key={game.key} asChild>
|
||||
<Link href={game.route}>
|
||||
<Icon />
|
||||
{game.label}
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
})}
|
||||
{cardtableGames.map(renderGame)}
|
||||
</DropdownMenuGroup>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuGroup>
|
||||
|
|
|
|||
44
src/components/frontend/minigames/MinigameComingSoon.tsx
Normal file
44
src/components/frontend/minigames/MinigameComingSoon.tsx
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { minigameIcon } from "@/components/frontend/minigames/minigameIcon";
|
||||
import { UpcomingCountdown } from "@/components/frontend/minigames/UpcomingCountdown";
|
||||
import { formatReleaseInstant } from "@/lib/minigames/countdown";
|
||||
import type { RegistryGame } from "@/lib/minigames/registry";
|
||||
|
||||
/**
|
||||
* Gate screen for a game whose registry status is "upcoming". Rendered by the
|
||||
* game pages in place of the arena so a typed URL cannot reach unfinished
|
||||
* gameplay. The countdown is display only; the game goes live when an admin
|
||||
* flips its status to Active.
|
||||
*/
|
||||
export function MinigameComingSoon({ game }: { game: RegistryGame }) {
|
||||
const Icon = minigameIcon(game.icon);
|
||||
const instant = formatReleaseInstant(game.estimatedReleaseDate ?? null);
|
||||
|
||||
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">
|
||||
<Icon className="size-5 text-muted-foreground" />
|
||||
<h1 className="text-lg font-semibold">{game.label}</h1>
|
||||
</div>
|
||||
{game.description && (
|
||||
<p className="text-sm text-muted-foreground">{game.description}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="w-full max-w-[520px] rounded-xl border border-border bg-card p-5">
|
||||
<p className="text-sm font-semibold">Coming soon</p>
|
||||
<p className="mt-2 text-sm text-muted-foreground">
|
||||
{instant ? (
|
||||
<>
|
||||
Estimated release{" "}
|
||||
<span className="text-foreground">{instant}</span> (
|
||||
<UpcomingCountdown estimatedReleaseDate={game.estimatedReleaseDate} />).
|
||||
</>
|
||||
) : (
|
||||
"An estimated release date has not been set yet. Check back later."
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
50
src/components/frontend/minigames/UpcomingCountdown.tsx
Normal file
50
src/components/frontend/minigames/UpcomingCountdown.tsx
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { formatCountdown, formatReleaseInstant, upcomingTooltip } from "@/lib/minigames/countdown";
|
||||
|
||||
export interface UpcomingCountdownProps {
|
||||
estimatedReleaseDate?: string | null;
|
||||
/**
|
||||
* "tooltip" renders the full "Upcoming · releases ... (in ...)" line used by
|
||||
* the disabled sidebar entry; "inline" renders just the remaining time, used
|
||||
* by the coming-soon screen.
|
||||
*/
|
||||
variant?: "tooltip" | "inline";
|
||||
className?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Live countdown text.
|
||||
*
|
||||
* The remaining time is derived from a `now` that only exists after mount:
|
||||
* computing it during SSR from `Date.now()` would mismatch the client and
|
||||
* trigger a hydration warning. Before the first tick the tooltip shows the
|
||||
* absolute instant and the inline variant shows a neutral placeholder.
|
||||
*/
|
||||
export function UpcomingCountdown({
|
||||
estimatedReleaseDate,
|
||||
variant = "inline",
|
||||
className,
|
||||
}: UpcomingCountdownProps) {
|
||||
const [now, setNow] = useState<Date | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setNow(new Date());
|
||||
const id = setInterval(() => setNow(new Date()), 1000);
|
||||
return () => clearInterval(id);
|
||||
}, [estimatedReleaseDate]);
|
||||
|
||||
if (variant === "tooltip") {
|
||||
if (!estimatedReleaseDate) return <span className={className}>Upcoming</span>;
|
||||
const instant = formatReleaseInstant(estimatedReleaseDate);
|
||||
if (!now) return <span className={className}>{`Upcoming · releases ${instant}`}</span>;
|
||||
return (
|
||||
<span className={className}>{upcomingTooltip(estimatedReleaseDate, now)}</span>
|
||||
);
|
||||
}
|
||||
|
||||
const countdown = now ? formatCountdown(estimatedReleaseDate ?? null, now) : null;
|
||||
return <span className={className}>{countdown ?? "coming soon"}</span>;
|
||||
}
|
||||
|
|
@ -50,3 +50,10 @@ code; the invariants are:
|
|||
- **Notifications**: winners are notified in-app on close (`minigame:achievement`, muteable);
|
||||
the Discord bot service `src/bot/services/achievementAnnouncements.ts` posts ONE embed per
|
||||
window to `DISCORD_ANNOUNCE_CHANNEL_ID` and stamps `announcedAt` + `discordMessageId`.
|
||||
- **Upcoming games**: a registry row with `status: "upcoming"` shows in the sidebar greyed out
|
||||
and non-interactive (a hoverable row, not a disabled menu item, because a disabled item sets
|
||||
`pointer-events: none` and would swallow its tooltip). The tooltip and the game page carry a
|
||||
countdown to the optional `estimatedReleaseDate`. Upcoming games are excluded from the
|
||||
leaderboards, and their page renders `MinigameComingSoon` instead of the arena. The date is
|
||||
display only: the game goes live when an admin flips `status` to active. Countdown formatting:
|
||||
`src/lib/minigames/countdown.ts`; page gate: `getMinigameReleaseState` plus a per-page check.
|
||||
|
|
|
|||
70
src/lib/minigames/countdown.ts
Normal file
70
src/lib/minigames/countdown.ts
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* Pure countdown formatting for upcoming minigames.
|
||||
*
|
||||
* No React and no Payload: the client ticker, the page gate and their tests all
|
||||
* share these functions. All instants are UTC, matching the rest of the feature.
|
||||
*/
|
||||
|
||||
const MINUTE_MS = 60_000;
|
||||
const HOUR_MS = 3_600_000;
|
||||
const DAY_MS = 86_400_000;
|
||||
|
||||
/** Format a release instant in UTC, e.g. "Dec 3, 2026 18:00 UTC". Null when unparseable. */
|
||||
export function formatReleaseInstant(iso: string | null | undefined): string | null {
|
||||
if (!iso) return null;
|
||||
const date = new Date(iso);
|
||||
if (Number.isNaN(date.getTime())) return null;
|
||||
const day = date.toLocaleDateString("en-US", {
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
year: "numeric",
|
||||
timeZone: "UTC",
|
||||
});
|
||||
const time = `${String(date.getUTCHours()).padStart(2, "0")}:${String(date.getUTCMinutes()).padStart(2, "0")}`;
|
||||
return `${day} ${time} UTC`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Human remaining time, e.g. "in 12d 3h", "in 3h 4m", "in 12m 30s", or
|
||||
* "any time now" once the estimate has passed. Null when there is no usable date.
|
||||
*/
|
||||
export function formatCountdown(
|
||||
iso: string | null | undefined,
|
||||
now: Date = new Date(),
|
||||
): string | null {
|
||||
if (!iso) return null;
|
||||
const target = new Date(iso).getTime();
|
||||
if (!Number.isFinite(target)) return null;
|
||||
|
||||
const remaining = target - now.getTime();
|
||||
if (remaining <= 0) return "any time now";
|
||||
|
||||
if (remaining >= DAY_MS) {
|
||||
const days = Math.floor(remaining / DAY_MS);
|
||||
const hours = Math.floor((remaining % DAY_MS) / HOUR_MS);
|
||||
return `in ${days}d ${hours}h`;
|
||||
}
|
||||
if (remaining >= HOUR_MS) {
|
||||
const hours = Math.floor(remaining / HOUR_MS);
|
||||
const minutes = Math.floor((remaining % HOUR_MS) / MINUTE_MS);
|
||||
return `in ${hours}h ${minutes}m`;
|
||||
}
|
||||
const minutes = Math.floor(remaining / MINUTE_MS);
|
||||
const seconds = Math.floor((remaining % MINUTE_MS) / 1000);
|
||||
return `in ${minutes}m ${seconds}s`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Full tooltip line for an upcoming game, e.g.
|
||||
* "Upcoming · releases Dec 3, 2026 18:00 UTC (in 12d 3h)". Reduces to just
|
||||
* "Upcoming" when no estimate is set.
|
||||
*/
|
||||
export function upcomingTooltip(
|
||||
estimatedReleaseDate: string | null | undefined,
|
||||
now: Date = new Date(),
|
||||
): string {
|
||||
const instant = formatReleaseInstant(estimatedReleaseDate);
|
||||
if (!instant) return "Upcoming";
|
||||
const countdown = formatCountdown(estimatedReleaseDate, now);
|
||||
return countdown ? `Upcoming · releases ${instant} (${countdown})` : `Upcoming · releases ${instant}`;
|
||||
}
|
||||
|
|
@ -38,6 +38,7 @@ export async function loadMinigameRegistry(payload: Payload): Promise<BuiltinMin
|
|||
order: typeof doc.order === "number" ? doc.order : 0,
|
||||
countsForPeriods: Boolean(doc.countsForPeriods),
|
||||
scoreLabel: doc.scoreLabel || "Score",
|
||||
estimatedReleaseDate: doc.estimatedReleaseDate ?? null,
|
||||
}),
|
||||
);
|
||||
if (rows.length > 0) return rows;
|
||||
|
|
@ -47,6 +48,25 @@ export async function loadMinigameRegistry(payload: Payload): Promise<BuiltinMin
|
|||
return [...BUILTIN_MINIGAMES];
|
||||
}
|
||||
|
||||
/**
|
||||
* Release state for one game, used by the page gate. `upcoming` games render a
|
||||
* coming-soon screen instead of gameplay.
|
||||
*/
|
||||
export interface MinigameReleaseState {
|
||||
/** Null when the key is not in the registry at all. */
|
||||
game: BuiltinMinigame | null;
|
||||
upcoming: boolean;
|
||||
}
|
||||
|
||||
export async function getMinigameReleaseState(
|
||||
payload: Payload,
|
||||
key: string,
|
||||
): Promise<MinigameReleaseState> {
|
||||
const games = await loadMinigameRegistry(payload);
|
||||
const game = games.find((entry) => entry.key === key) ?? null;
|
||||
return { game, upcoming: game?.status === "upcoming" };
|
||||
}
|
||||
|
||||
/** Games visible in the nav: everything not retired, in registry order. */
|
||||
export function visibleRegistryGames(games: BuiltinMinigame[]): BuiltinMinigame[] {
|
||||
return games.filter((game) => game.status !== "retired");
|
||||
|
|
|
|||
|
|
@ -249,13 +249,16 @@ export async function buildLeaderboardPayload(
|
|||
const rules = await resolveMinigameRules(payload);
|
||||
const registry = await loadMinigameRegistry(payload);
|
||||
const allTime = query.scope === "all-time";
|
||||
// Upcoming games are not shown on the leaderboards (they have no board and
|
||||
// their sidebar entry is disabled), so they get neither a tab nor rows.
|
||||
const playable = registry.filter((game) => game.status !== "upcoming");
|
||||
|
||||
const boards = allTime
|
||||
? await buildAllTimeBoards(payload, registry)
|
||||
? await buildAllTimeBoards(payload, playable)
|
||||
: await buildPeriodBoards(
|
||||
payload,
|
||||
query.periodId ?? null,
|
||||
registry.filter((game) => game.category === "core"),
|
||||
playable.filter((game) => game.category === "core"),
|
||||
rules.placementLadderTopN,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,12 @@ export interface BuiltinMinigame {
|
|||
countsForPeriods: boolean;
|
||||
/** Label for the score column, e.g. "Passes", "Time". */
|
||||
scoreLabel: string;
|
||||
/**
|
||||
* Optional target release instant (ISO 8601, UTC) shown as a countdown while
|
||||
* `status` is "upcoming". Display only: the game goes live when an admin
|
||||
* changes `status` to "active", so a slipped estimate never exposes it.
|
||||
*/
|
||||
estimatedReleaseDate?: string | null;
|
||||
}
|
||||
|
||||
/** The seven built-in games, seeded into the `minigames` registry collection. */
|
||||
|
|
|
|||
39989
src/migrations/20261011_221250_add_minigame_estimated_release_date.json
Normal file
39989
src/migrations/20261011_221250_add_minigame_estimated_release_date.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,11 @@
|
|||
import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
|
||||
|
||||
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
|
||||
await db.execute(sql`
|
||||
ALTER TABLE "minigames" ADD COLUMN "estimated_release_date" timestamp(3) with time zone;`)
|
||||
}
|
||||
|
||||
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
|
||||
await db.execute(sql`
|
||||
ALTER TABLE "minigames" DROP COLUMN "estimated_release_date";`)
|
||||
}
|
||||
|
|
@ -123,6 +123,7 @@ import * as migration_20261010_050644_add_mission_threat_assessment from './2026
|
|||
import * as migration_20261011_195306_add_minigame_periods from './20261011_195306_add_minigame_periods';
|
||||
import * as migration_20261011_201531_add_minigame_entry_occurred_at from './20261011_201531_add_minigame_entry_occurred_at';
|
||||
import * as migration_20261011_221111_add_call_for_fire_minigame from './20261011_221111_add_call_for_fire_minigame';
|
||||
import * as migration_20261011_221250_add_minigame_estimated_release_date from './20261011_221250_add_minigame_estimated_release_date';
|
||||
|
||||
export const migrations = [
|
||||
{
|
||||
|
|
@ -743,11 +744,16 @@ export const migrations = [
|
|||
{
|
||||
up: migration_20261011_201531_add_minigame_entry_occurred_at.up,
|
||||
down: migration_20261011_201531_add_minigame_entry_occurred_at.down,
|
||||
name: '20261011_201531_add_minigame_entry_occurred_at'
|
||||
name: '20261011_201531_add_minigame_entry_occurred_at',
|
||||
},
|
||||
{
|
||||
up: migration_20261011_221111_add_call_for_fire_minigame.up,
|
||||
down: migration_20261011_221111_add_call_for_fire_minigame.down,
|
||||
name: '20261011_221111_add_call_for_fire_minigame'
|
||||
name: '20261011_221111_add_call_for_fire_minigame',
|
||||
},
|
||||
{
|
||||
up: migration_20261011_221250_add_minigame_estimated_release_date.up,
|
||||
down: migration_20261011_221250_add_minigame_estimated_release_date.down,
|
||||
name: '20261011_221250_add_minigame_estimated_release_date',
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -6005,6 +6005,10 @@ export interface Minigame {
|
|||
icon?: string | null;
|
||||
category: 'core' | 'cardtable';
|
||||
status: 'active' | 'upcoming' | 'retired';
|
||||
/**
|
||||
* Optional target for an upcoming game. Shown as a countdown in the sidebar and on the game page. Display only: the game goes live when status changes to Active.
|
||||
*/
|
||||
estimatedReleaseDate?: string | null;
|
||||
order: number;
|
||||
/**
|
||||
* When on, ledger entries for this game feed anchored period boards.
|
||||
|
|
@ -10747,6 +10751,7 @@ export interface MinigamesSelect<T extends boolean = true> {
|
|||
icon?: T;
|
||||
category?: T;
|
||||
status?: T;
|
||||
estimatedReleaseDate?: T;
|
||||
order?: T;
|
||||
countsForPeriods?: T;
|
||||
scoreLabel?: T;
|
||||
|
|
|
|||
99
tests/e2e/minigame-upcoming.e2e.spec.ts
Normal file
99
tests/e2e/minigame-upcoming.e2e.spec.ts
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
import { expect, test, type APIRequestContext } from "@playwright/test";
|
||||
|
||||
/**
|
||||
* Upcoming-game treatment: a registry row with `status: "upcoming"` is shown
|
||||
* greyed out and non-interactive in the sidebar with a countdown tooltip, and
|
||||
* its game page renders the coming-soon gate instead of the arena.
|
||||
*
|
||||
* The test seeds its own registry rows over the REST API (the e2e database is
|
||||
* seeded from the schema push, which does not run the registry migration) and
|
||||
* deletes them again, so other specs see the built-in fallback list.
|
||||
*/
|
||||
|
||||
const RELEASE = new Date(Date.now() + 12 * 86_400_000 + 3 * 3_600_000).toISOString();
|
||||
|
||||
const seedGame = async (
|
||||
request: APIRequestContext,
|
||||
game: { key: string; label: string; status: "active" | "upcoming"; route: string },
|
||||
): Promise<number> => {
|
||||
const res = await request.post("/api/minigames", {
|
||||
data: {
|
||||
key: game.key,
|
||||
label: game.label,
|
||||
description: "e2e upcoming game",
|
||||
route: game.route,
|
||||
icon: "Radio",
|
||||
category: "core",
|
||||
status: game.status,
|
||||
order: 90,
|
||||
countsForPeriods: false,
|
||||
scoreLabel: "Score",
|
||||
estimatedReleaseDate: RELEASE,
|
||||
},
|
||||
});
|
||||
expect(res.status(), `seed ${game.key}: ${await res.text()}`).toBeLessThan(400);
|
||||
const body = (await res.json()) as { doc?: { id: number } };
|
||||
expect(body.doc?.id, `seed ${game.key} returned no id`).toBeTruthy();
|
||||
return body.doc!.id;
|
||||
};
|
||||
|
||||
const deleteGame = async (request: APIRequestContext, id: number) => {
|
||||
await request.delete(`/api/minigames/${id}`);
|
||||
};
|
||||
|
||||
test.describe("Upcoming minigames", () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto("/login");
|
||||
await page.getByLabel("Username").fill("dev");
|
||||
await page.getByLabel("Password").fill("Test123");
|
||||
await page.getByRole("button", { name: "Log in" }).click();
|
||||
await page.waitForURL((url) => !url.pathname.startsWith("/login"), { timeout: 30_000 });
|
||||
});
|
||||
|
||||
test("shows a disabled sidebar entry with a countdown tooltip", async ({ page }) => {
|
||||
const id = await seedGame(page.request, {
|
||||
key: "signals-e2e",
|
||||
label: "Signals Intercept",
|
||||
status: "upcoming",
|
||||
route: "/minigames/leaderboards",
|
||||
});
|
||||
|
||||
try {
|
||||
await page.goto("/");
|
||||
await page.getByRole("button", { name: "Minigames" }).click();
|
||||
|
||||
const entry = page.getByText("Signals Intercept");
|
||||
await expect(entry).toBeVisible();
|
||||
// Non-interactive: the row is not a link and not a menu item.
|
||||
await expect(page.getByRole("menuitem", { name: /Signals Intercept/ })).toHaveCount(0);
|
||||
|
||||
await entry.hover();
|
||||
const tooltip = page.getByRole("tooltip");
|
||||
await expect(tooltip).toContainText("Upcoming · releases");
|
||||
await expect(tooltip).toContainText(/in \d+[dhms]/);
|
||||
} finally {
|
||||
await deleteGame(page.request, id);
|
||||
}
|
||||
});
|
||||
|
||||
test("gates the game page with a coming-soon screen", async ({ page }) => {
|
||||
const id = await seedGame(page.request, {
|
||||
key: "flappy",
|
||||
label: "Flight Simulator",
|
||||
status: "upcoming",
|
||||
route: "/minigames/flappy",
|
||||
});
|
||||
|
||||
try {
|
||||
await page.goto("/minigames/flappy");
|
||||
// exact: true keeps this from also matching the countdown's "coming soon"
|
||||
// placeholder text.
|
||||
await expect(page.getByText("Coming soon", { exact: true })).toBeVisible();
|
||||
await expect(page.getByText(/Estimated release/)).toBeVisible();
|
||||
// The playable arena is not rendered.
|
||||
await expect(page.getByText("Tap or press Space to flap")).toHaveCount(0);
|
||||
} finally {
|
||||
await deleteGame(page.request, id);
|
||||
}
|
||||
});
|
||||
});
|
||||
40
tests/int/minigame-countdown.int.spec.ts
Normal file
40
tests/int/minigame-countdown.int.spec.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
formatCountdown,
|
||||
formatReleaseInstant,
|
||||
upcomingTooltip,
|
||||
} from "@/lib/minigames/countdown";
|
||||
|
||||
const TARGET = "2026-12-03T18:00:00.000Z";
|
||||
const targetMs = new Date(TARGET).getTime();
|
||||
const MINUTE = 60_000;
|
||||
const HOUR = 3_600_000;
|
||||
const DAY = 86_400_000;
|
||||
|
||||
describe("Minigame release countdown", () => {
|
||||
it("formats the release instant in UTC", () => {
|
||||
expect(formatReleaseInstant(TARGET)).toBe("Dec 3, 2026 18:00 UTC");
|
||||
expect(formatReleaseInstant(null)).toBeNull();
|
||||
expect(formatReleaseInstant("not-a-date")).toBeNull();
|
||||
});
|
||||
|
||||
it("formats remaining time by magnitude", () => {
|
||||
expect(formatCountdown(TARGET, new Date(targetMs - (12 * DAY + 3 * HOUR)))).toBe("in 12d 3h");
|
||||
expect(formatCountdown(TARGET, new Date(targetMs - (3 * HOUR + 4 * MINUTE)))).toBe("in 3h 4m");
|
||||
expect(formatCountdown(TARGET, new Date(targetMs - (12 * MINUTE + 30_000)))).toBe("in 12m 30s");
|
||||
expect(formatCountdown(null)).toBeNull();
|
||||
expect(formatCountdown("nope")).toBeNull();
|
||||
});
|
||||
|
||||
it("settles on 'any time now' once the estimate has passed", () => {
|
||||
expect(formatCountdown(TARGET, new Date(targetMs))).toBe("any time now");
|
||||
expect(formatCountdown(TARGET, new Date(targetMs + HOUR))).toBe("any time now");
|
||||
});
|
||||
|
||||
it("builds the tooltip line, with and without an estimate", () => {
|
||||
expect(upcomingTooltip(TARGET, new Date(targetMs - (12 * DAY + 3 * HOUR)))).toBe(
|
||||
"Upcoming · releases Dec 3, 2026 18:00 UTC (in 12d 3h)",
|
||||
);
|
||||
expect(upcomingTooltip(null)).toBe("Upcoming");
|
||||
});
|
||||
});
|
||||
105
tests/int/minigame-upcoming.int.spec.ts
Normal file
105
tests/int/minigame-upcoming.int.spec.ts
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
import { getPayload, Payload } from "payload";
|
||||
import config from "@/payload.config";
|
||||
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { loadMinigameRegistry, getMinigameReleaseState } from "@/lib/minigames/loadRegistry";
|
||||
import { buildLeaderboardPayload } from "@/lib/minigames/periods/standings";
|
||||
|
||||
const RUN = `mgup-${Date.now().toString(36)}`;
|
||||
const RELEASE = "2026-12-03T18:00:00.000Z";
|
||||
|
||||
let payload: Payload;
|
||||
let originalRules: Record<string, unknown> | null = null;
|
||||
|
||||
describe("Upcoming minigames", () => {
|
||||
beforeAll(async () => {
|
||||
const payloadConfig = await config;
|
||||
payload = await getPayload({ config: payloadConfig });
|
||||
await clearMinigameData();
|
||||
|
||||
originalRules = (await payload.findGlobal({
|
||||
slug: "minigame-rules",
|
||||
depth: 0,
|
||||
overrideAccess: true,
|
||||
})) as unknown as Record<string, unknown> | null;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await clearMinigameData();
|
||||
if (!originalRules) return;
|
||||
await payload
|
||||
.updateGlobal({
|
||||
slug: "minigame-rules",
|
||||
data: {
|
||||
enabled: Boolean(originalRules.enabled),
|
||||
anchorDate: originalRules.anchorDate as string,
|
||||
periodLengthDays: (originalRules.periodLengthDays as number) ?? 14,
|
||||
placementLadderTopN: (originalRules.placementLadderTopN as number) ?? 10,
|
||||
precisionMinAttempts: (originalRules.precisionMinAttempts as number) ?? 5,
|
||||
},
|
||||
overrideAccess: true,
|
||||
})
|
||||
.catch(() => undefined);
|
||||
});
|
||||
|
||||
it("round-trips the estimated release date and reports the gate state", async () => {
|
||||
await createGame({ key: "signals", label: "Signals Intercept", status: "upcoming", order: 1, estimatedReleaseDate: RELEASE });
|
||||
await createGame({ key: "flappy", label: "Flight Simulator", status: "active", order: 2 });
|
||||
|
||||
const games = await loadMinigameRegistry(payload);
|
||||
const signals = games.find((game) => game.key === "signals");
|
||||
expect(signals?.estimatedReleaseDate).toBe(RELEASE);
|
||||
|
||||
const upcoming = await getMinigameReleaseState(payload, "signals");
|
||||
expect(upcoming.upcoming).toBe(true);
|
||||
expect(upcoming.game?.label).toBe("Signals Intercept");
|
||||
|
||||
const active = await getMinigameReleaseState(payload, "flappy");
|
||||
expect(active.upcoming).toBe(false);
|
||||
|
||||
const missing = await getMinigameReleaseState(payload, "does-not-exist");
|
||||
expect(missing.upcoming).toBe(false);
|
||||
expect(missing.game).toBeNull();
|
||||
});
|
||||
|
||||
it("leaves an upcoming game off the leaderboards", async () => {
|
||||
const data = await buildLeaderboardPayload(payload, { scope: "period" });
|
||||
const keys = data.boards.map((board) => board.key);
|
||||
expect(keys).toContain("flappy");
|
||||
expect(keys).not.toContain("signals");
|
||||
});
|
||||
|
||||
async function createGame(data: {
|
||||
key: string;
|
||||
label: string;
|
||||
status: "active" | "upcoming" | "retired";
|
||||
order: number;
|
||||
estimatedReleaseDate?: string;
|
||||
}) {
|
||||
await payload.create({
|
||||
collection: "minigames",
|
||||
data: {
|
||||
...data,
|
||||
route: `/minigames/${data.key}`,
|
||||
icon: "Radio",
|
||||
category: "core",
|
||||
scoreLabel: "Score",
|
||||
description: "",
|
||||
countsForPeriods: false,
|
||||
},
|
||||
overrideAccess: true,
|
||||
depth: 0,
|
||||
});
|
||||
}
|
||||
|
||||
async function clearMinigameData() {
|
||||
for (const collection of [
|
||||
"achievements",
|
||||
"minigame-entries",
|
||||
"minigame-periods",
|
||||
"minigames",
|
||||
] as const) {
|
||||
await payload.delete({ collection, where: { id: { greater_than: 0 } }, overrideAccess: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
Loading…
Reference in a new issue