"use client"; import LeaderboardScores from "@/components/leaderboard/leaderboard-scores"; import { LeaderboardInfo } from "@/components/leaderboard/leaderboard-info"; import ScoreSaberScore from "@ssr/common/score/impl/scoresaber-score"; import ScoreSaberLeaderboard from "@ssr/common/leaderboard/impl/scoresaber-leaderboard"; import { LeaderboardResponse } from "@ssr/common/response/leaderboard-response"; import { useQuery } from "@tanstack/react-query"; import { useState } from "react"; import { fetchLeaderboard } from "@ssr/common/utils/leaderboard.util"; import PlayerScoresResponse from "../../../../common/src/response/player-scores-response.ts"; const REFRESH_INTERVAL = 1000 * 60 * 5; type LeaderboardDataProps = { /** * The initial leaderboard data. */ initialLeaderboard: LeaderboardResponse; /** * The initial score data. */ initialScores: PlayerScoresResponse; }; export function LeaderboardData({ initialLeaderboard, initialScores }: LeaderboardDataProps) { const [currentLeaderboardId, setCurrentLeaderboardId] = useState(initialLeaderboard.leaderboard.id); let leaderboard = initialLeaderboard; const { data, isLoading, isError } = useQuery({ queryKey: ["leaderboard", currentLeaderboardId], queryFn: async (): Promise | undefined> => { return fetchLeaderboard("scoresaber", currentLeaderboardId + ""); }, refetchInterval: REFRESH_INTERVAL, refetchIntervalInBackground: false, }); if (data && (!isLoading || !isError)) { leaderboard = data; } return (
setCurrentLeaderboardId(newId)} showDifficulties isLeaderboardPage />
); }