diff --git a/src/common/leaderboards.ts b/src/common/leaderboards.ts new file mode 100644 index 0000000..da80bcc --- /dev/null +++ b/src/common/leaderboards.ts @@ -0,0 +1,19 @@ +import ScoreSaberPlayer from "@/common/data-fetcher/types/scoresaber/scoresaber-player"; +import { scoresaberFetcher } from "@/common/data-fetcher/impl/scoresaber"; +import { ScoreSort } from "@/common/data-fetcher/sort"; + +export const leaderboards = { + ScoreSaber: { + capabilities: { + search: true, + }, + queries: { + lookupScores: (player: ScoreSaberPlayer, sort: ScoreSort, page: number) => + scoresaberFetcher.lookupPlayerScores({ + playerId: player.id, + sort: sort, + page: page, + }), + }, + }, +}; diff --git a/src/components/player/player-scores.tsx b/src/components/player/player-scores.tsx index 2612725..cdae9ee 100644 --- a/src/components/player/player-scores.tsx +++ b/src/components/player/player-scores.tsx @@ -14,6 +14,7 @@ import Card from "../card"; import Pagination from "../input/pagination"; import { Button } from "../ui/button"; import Score from "./score/score"; +import { leaderboards } from "@/common/leaderboards"; type Props = { initialScoreData?: ScoreSaberPlayerScoresPage; @@ -34,22 +35,6 @@ type PageState = { sort: ScoreSort; }; -const leaderboards = { - ScoreSaber: { - capabilities: { - search: true, - }, - queries: { - lookupScores: (player: ScoreSaberPlayer, pageState: PageState) => - scoresaberFetcher.lookupPlayerScores({ - playerId: player.id, - sort: ScoreSort.top, - page: 1, - }), - }, - }, -}; - const scoreSort = [ { name: "Top", @@ -114,7 +99,8 @@ export default function PlayerScores({ refetch, } = useQuery({ queryKey: ["playerScores", player.id, leaderboard, pageState], - queryFn: () => leaderboard.queries.lookupScores(player, pageState), + queryFn: () => + leaderboard.queries.lookupScores(player, pageState.sort, pageState.page), staleTime: 30 * 1000, // Cache data for 30 seconds }); diff --git a/src/components/player/player-stats.tsx b/src/components/player/player-stats.tsx index cc8aaac..8d8ecfb 100644 --- a/src/components/player/player-stats.tsx +++ b/src/components/player/player-stats.tsx @@ -5,7 +5,7 @@ import { ClassValue } from "clsx"; type Badge = { name: string; - color?: ClassValue; + color?: string; create: (player: ScoreSaberPlayer) => string | React.ReactNode | undefined; };