import { desc } from "drizzle-orm"; import type { Metadata } from "next"; import { getTranslations } from "next-intl/server"; import Link from "@/components/link"; import { PublicLoadError } from "@/components/public/load-error"; import { ContentCard, EmptyState, OnlineBadge, RankBadge, } from "@/components/public/ui"; import { CurrencyIcon } from "@/components/shared/currency-icon"; import { UserAvatarThumbnail } from "@/components/shared/user-avatar-thumbnail"; import { cached } from "@/lib/cache"; import { db, User } from "@/lib/db"; import { publicReadFailure } from "@/lib/services/public-read"; export async function generateMetadata(): Promise { const t = await getTranslations("pages.rankings"); return { title: t("title"), description: t("subtitle"), openGraph: { title: t("title"), description: t("subtitle"), type: "website", }, }; } type TopUser = { username: string; look: string; credits: number; rank: number; online: string; }; export default async function RankingsPage() { const t = await getTranslations("pages.rankings"); let users: TopUser[] | null = []; try { users = await cached( "rankings:top", 60_000, async () => db .select({ username: User.username, look: User.look, credits: User.credits, rank: User.rank, online: User.online, }) .from(User) .orderBy(desc(User.credits)) .limit(12), { staleMs: 120000 }, ); } catch (error) { users = publicReadFailure("rankings")(error); } return (
{users === null ? ( ) : users.length === 0 ? ( {t("emptyState")} ) : (
{users.map((u, i) => { return (

{u.username}

{u.credits.toLocaleString()}

); })}
)}
); }