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 Pagination from "../input/pagination";
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
import Score from "./score/score";
|
import Score from "./score/score";
|
||||||
|
import { leaderboards } from "@/common/leaderboards";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
initialScoreData?: ScoreSaberPlayerScoresPage;
|
initialScoreData?: ScoreSaberPlayerScoresPage;
|
||||||
@ -34,22 +35,6 @@ type PageState = {
|
|||||||
sort: ScoreSort;
|
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 = [
|
const scoreSort = [
|
||||||
{
|
{
|
||||||
name: "Top",
|
name: "Top",
|
||||||
@ -114,7 +99,8 @@ export default function PlayerScores({
|
|||||||
refetch,
|
refetch,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ["playerScores", player.id, leaderboard, pageState],
|
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
|
staleTime: 30 * 1000, // Cache data for 30 seconds
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import { ClassValue } from "clsx";
|
|||||||
|
|
||||||
type Badge = {
|
type Badge = {
|
||||||
name: string;
|
name: string;
|
||||||
color?: ClassValue;
|
color?: string;
|
||||||
create: (player: ScoreSaberPlayer) => string | React.ReactNode | undefined;
|
create: (player: ScoreSaberPlayer) => string | React.ReactNode | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user