This commit is contained in:
parent
dd3b7256b0
commit
709d51b00e
19
src/common/leaderboards.ts
Normal file
19
src/common/leaderboards.ts
Normal file
@ -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,
|
||||
}),
|
||||
},
|
||||
},
|
||||
};
|
@ -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
|
||||
});
|
||||
|
||||
|
@ -5,7 +5,7 @@ import { ClassValue } from "clsx";
|
||||
|
||||
type Badge = {
|
||||
name: string;
|
||||
color?: ClassValue;
|
||||
color?: string;
|
||||
create: (player: ScoreSaberPlayer) => string | React.ReactNode | undefined;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user