Add player leaderboard and homepage preview

This commit is contained in:
2026-10-06 15:21:49 +05:00
parent 2bbf5ae2c0
commit 949aa6627a
25 changed files with 2363 additions and 28 deletions

36
lib/leaderboard.ts Normal file
View File

@@ -0,0 +1,36 @@
import "server-only";
import { admin, required } from "./supabase";
import type {
LeaderboardData,
LeaderboardDifficulty,
} from "@/shared/leaderboard";
export async function leaderboard({
difficulty = "all",
search = "",
page = 1,
limit = 25,
}: {
difficulty?: LeaderboardDifficulty;
search?: string;
page?: number;
limit?: number;
} = {}): Promise<LeaderboardData | null> {
try {
return required(
await admin().rpc("player_leaderboard", {
p_difficulty: difficulty,
p_search: search,
p_page: page,
p_limit: limit,
}),
) as unknown as LeaderboardData;
} catch (error) {
// A leaderboard outage must not take the map catalog or homepage offline.
console.error(
"Leaderboard query failed",
error instanceof Error ? error.message : "Unknown error",
);
return null;
}
}