1
0
Fork 0
polaris-task-force/src/components/frontend/blocks/NavMinigames.tsx
Z8MB1E 0bb9719139 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.
2026-10-11 18:47:43 -04:00

118 lines
4.1 KiB
TypeScript

"use client";
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,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import {
SidebarMenuButton,
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();
const visible = games.filter((game) => game.status !== "retired");
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>
<DropdownMenuTrigger asChild>
<SidebarMenuButton size="sm">
<Gamepad2 />
<span>Minigames</span>
<ChevronRight className="ml-auto size-4 text-sidebar-foreground/50" />
</SidebarMenuButton>
</DropdownMenuTrigger>
<DropdownMenuContent
className="w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg"
side={isMobile ? "bottom" : "right"}
align="end"
sideOffset={4}
>
<DropdownMenuGroup>
<DropdownMenuLabel>Core</DropdownMenuLabel>
{coreGames.map(renderGame)}
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuLabel className="flex flex-col">
<span>Cardtable</span>
<span className="text-xs font-normal text-muted-foreground">Earn chips to spend by playing Core minigames!</span>
</DropdownMenuLabel>
{cardtableGames.map(renderGame)}
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem asChild>
<Link href="/minigames/leaderboards">
<Trophy />
Leaderboards
</Link>
</DropdownMenuItem>
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
</SidebarMenuItem>
);
}