"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 { useEffect, useState } from "react"; import { fetchLeaderboard } from "@ssr/common/utils/leaderboard.util"; import LeaderboardScoresResponse from "@ssr/common/response/leaderboard-scores-response"; import LeaderboardPpChart from "@/components/leaderboard/leaderboard-pp-chart"; import Card from "@/components/card"; type LeaderboardDataProps = { /** * The initial leaderboard data. */ initialLeaderboard: LeaderboardResponse; /** * The initial score data. */ initialScores?: LeaderboardScoresResponse; /** * The initial page. */ initialPage?: number; }; export function LeaderboardData({ initialLeaderboard, initialScores, initialPage }: LeaderboardDataProps) { const [currentLeaderboardId, setCurrentLeaderboardId] = useState(initialLeaderboard.leaderboard.id); const [currentLeaderboard, setCurrentLeaderboard] = useState(initialLeaderboard); const { data, isLoading, isError } = useQuery({ queryKey: ["leaderboard", currentLeaderboardId], queryFn: async (): Promise | undefined> => { return fetchLeaderboard("scoresaber", currentLeaderboardId + ""); }, }); useEffect(() => { if (data) { setCurrentLeaderboard(data); } }, [data]); const leaderboard = currentLeaderboard.leaderboard; return (
setCurrentLeaderboardId(newId)} showDifficulties isLeaderboardPage />
{leaderboard.stars > 0 && }
); }