Table components, popup system, dev panel, and the actions/page wiring, with popup, table, and dev-control tests. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
84 lines
2.7 KiB
TypeScript
84 lines
2.7 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 { Spade } from "lucide-react";
|
|
import { PokerArena } from "@/components/frontend/minigames/poker/PokerArena";
|
|
import { readPokerStats } from "@/lib/minigames/poker/stats";
|
|
import { isSuperuser, superuserUserIds } from "@/utils/access-control/hasPermission";
|
|
|
|
export const metadata: Metadata = {
|
|
title: "Poker: Polaris Task Force",
|
|
description: "A multiplayer Texas Hold'em training table for Polaris Task Force operators.",
|
|
};
|
|
|
|
interface PokerPageProps {
|
|
searchParams: Promise<{
|
|
table?: string | string[];
|
|
}>;
|
|
}
|
|
|
|
export default async function PokerPage({ searchParams }: PokerPageProps) {
|
|
const headers = await nextHeaders();
|
|
const payload = await getPayload({ config });
|
|
const { user } = await payload.auth({ headers, canSetHeaders: false });
|
|
|
|
if (!user) {
|
|
redirect(`/login?returnTo=${encodeURIComponent("/minigames/poker")}`);
|
|
}
|
|
|
|
const superuser = await isSuperuser(payload, user);
|
|
const superuserIds = await superuserUserIds(payload);
|
|
|
|
const profileRes = await payload.find({
|
|
collection: "profiles",
|
|
where: { user: { equals: Number(user.id) } },
|
|
limit: 1,
|
|
depth: 0,
|
|
overrideAccess: true,
|
|
select: {
|
|
progression: {
|
|
minigames: true,
|
|
chipBank: true,
|
|
chipBankRefilledAt: true,
|
|
},
|
|
},
|
|
});
|
|
|
|
const stats = readPokerStats(profileRes.docs[0]);
|
|
const progressionDoc = (profileRes.docs[0]?.progression ?? {}) as {
|
|
chipBank?: number | null;
|
|
chipBankRefilledAt?: string | null;
|
|
};
|
|
const initialChipBank = progressionDoc.chipBank ?? 0;
|
|
const initialChipTopUpAt = progressionDoc.chipBankRefilledAt ?? null;
|
|
const params = await searchParams;
|
|
const tableValue = params.table;
|
|
const initialTableId = Array.isArray(tableValue) ? tableValue[0] : tableValue;
|
|
|
|
return (
|
|
<div className="flex flex-col gap-6 p-5">
|
|
<div className="flex flex-col gap-1">
|
|
<div className="flex items-center gap-2">
|
|
<Spade className="size-5 text-muted-foreground" />
|
|
<h1 className="text-lg font-semibold">Poker</h1>
|
|
</div>
|
|
<p className="text-sm text-muted-foreground">
|
|
Sit down for a multiplayer Texas Hold'em game. Read the table, manage your stack, and
|
|
outlast the field.
|
|
</p>
|
|
</div>
|
|
|
|
<PokerArena
|
|
initialStats={stats}
|
|
currentUserId={Number(user.id)}
|
|
initialTableId={initialTableId}
|
|
isSuperuser={superuser}
|
|
superuserIds={superuserIds}
|
|
initialChipBank={initialChipBank}
|
|
initialChipTopUpAt={initialChipTopUpAt}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|