import { getI18n } from "@/lib/i18n"; import { Header, Footer } from "@/components/Shell"; import { SignIn } from "@/components/SignIn"; import { Dashboard } from "@/components/Dashboard"; import { admin, user, required } from "@/lib/supabase"; import Link from "next/link"; import { accountProfile } from "@/lib/profile"; import { Username } from "@/components/Username"; export const dynamic = "force-dynamic"; export default async function DashboardPage() { const { t, formatDate } = await getI18n(); const account = await user(); const profile = account ? await accountProfile(account) : null; const historyCutoff = new Date( Date.now() - 30 * 24 * 60 * 60 * 1000, ).toISOString(); const history = account ? required( await admin() .from("game_sessions") .select("id,difficulty,difficulty_settings,created_at,current_round") .eq("owner_id", account.id) .gte("created_at", historyCutoff) .order("created_at", { ascending: false }) .limit(5), ) : []; return ( <>
{account ? ( <> {t("THE CARTOGRAPHER’S DESK")}

{t("My expedition.")}

{t("Welcome back,")}{" "} .

{history.length > 0 && (

{t("Recent journeys")}

{t("Your five latest journeys from the past 30 days.")}

{history.map((s) => (
{formatDate(s.created_at)} ·{" "} {s.difficulty_settings && typeof s.difficulty_settings === "object" && !Array.isArray(s.difficulty_settings) && typeof s.difficulty_settings.name === "string" ? ["easy", "normal", "hard"].includes(s.difficulty) ? t(s.difficulty_settings.name) : s.difficulty_settings.name : t( s.difficulty[0].toUpperCase() + s.difficulty.slice(1), )}{" "} · {s.current_round} {t("/5 rounds")} = 5 ? "results" : "play"}/${s.id}`} > {t("Open →")}
))}
)} ) : ( )}