From 1733822bab4f9e06a1b81b83b511dcc84970c95c Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 28 Sep 2024 12:59:54 +0100 Subject: [PATCH] fix search --- src/common/leaderboards.ts | 24 ------------------------ src/components/input/search-player.tsx | 2 +- src/components/player/player-scores.tsx | 11 +++++++---- src/components/ranking/mini.tsx | 9 +++------ 4 files changed, 11 insertions(+), 35 deletions(-) delete mode 100644 src/common/leaderboards.ts diff --git a/src/common/leaderboards.ts b/src/common/leaderboards.ts deleted file mode 100644 index cd43216..0000000 --- a/src/common/leaderboards.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { scoresaberService } from "@/common/service/impl/scoresaber"; -import { ScoreSort } from "@/common/service/score-sort"; -import ScoreSaberPlayer from "@/common/model/player/impl/scoresaber-player"; - -export const leaderboards = { - ScoreSaber: { - capabilities: { - search: true, - }, - queries: { - lookupScores: (player: ScoreSaberPlayer, sort: ScoreSort, page: number) => - scoresaberService.lookupPlayerScores({ - playerId: player.id, - sort: sort, - page: page, - }), - - lookupGlobalPlayers: (page: number) => - scoresaberService.lookupPlayers(page), - lookupGlobalPlayersByCountry: (page: number, country: string) => - scoresaberService.lookupPlayersByCountry(page, country), - }, - }, -}; diff --git a/src/components/input/search-player.tsx b/src/components/input/search-player.tsx index affbbe1..c976343 100644 --- a/src/components/input/search-player.tsx +++ b/src/components/input/search-player.tsx @@ -15,7 +15,7 @@ import { Input } from "../ui/input"; import { ScrollArea } from "../ui/scroll-area"; const formSchema = z.object({ - username: z.string().min(2).max(50), + username: z.string().min(3).max(50), }); export default function SearchPlayer() { diff --git a/src/components/player/player-scores.tsx b/src/components/player/player-scores.tsx index 2b8cf47..8cf5bf8 100644 --- a/src/components/player/player-scores.tsx +++ b/src/components/player/player-scores.tsx @@ -9,11 +9,11 @@ import { useCallback, useEffect, useState } from "react"; import Card from "../card"; import Pagination from "../input/pagination"; import { Button } from "../ui/button"; -import { leaderboards } from "@/common/leaderboards"; import { ScoreSort } from "@/common/service/score-sort"; import ScoreSaberPlayerScoresPageToken from "@/common/model/token/scoresaber/score-saber-player-scores-page-token"; import Score from "@/components/score/score"; import ScoreSaberPlayer from "@/common/model/player/impl/scoresaber-player"; +import { scoresaberService } from "@/common/service/impl/scoresaber"; type Props = { initialScoreData?: ScoreSaberPlayerScoresPageToken; @@ -77,7 +77,6 @@ export default function PlayerScores({ sort, page, }: Props) { - const leaderboard = leaderboards.ScoreSaber; const { width } = useWindowDimensions(); const controls = useAnimation(); @@ -97,9 +96,13 @@ export default function PlayerScores({ isLoading, refetch, } = useQuery({ - queryKey: ["playerScores", player.id, leaderboard, pageState], + queryKey: ["playerScores", player.id, pageState], queryFn: () => - leaderboard.queries.lookupScores(player, pageState.sort, pageState.page), + scoresaberService.lookupPlayerScores({ + playerId: player.id, + sort: pageState.sort, + page: pageState.page, + }), staleTime: 30 * 1000, // Cache data for 30 seconds }); diff --git a/src/components/ranking/mini.tsx b/src/components/ranking/mini.tsx index ce2d197..ebda7e1 100644 --- a/src/components/ranking/mini.tsx +++ b/src/components/ranking/mini.tsx @@ -1,4 +1,3 @@ -import { leaderboards } from "@/common/leaderboards"; import ScoreSaberPlayerToken from "@/common/model/token/scoresaber/score-saber-player-token"; import { ScoreSaberPlayersPageToken } from "@/common/model/token/scoresaber/score-saber-players-page-token"; import { formatNumberWithCommas, formatPp } from "@/common/number-utils"; @@ -10,6 +9,7 @@ import Card from "../card"; import CountryFlag from "../country-flag"; import { Avatar, AvatarImage } from "../ui/avatar"; import ScoreSaberPlayer from "@/common/model/player/impl/scoresaber-player"; +import { scoresaberService } from "@/common/service/impl/scoresaber"; const REFRESH_INTERVAL = 5 * 60 * 1000; // 5 minutes const PLAYER_NAME_MAX_LENGTH = 18; @@ -39,7 +39,7 @@ const miniVariants: Variants = { return Math.floor((player.rank - 1) / itemsPerPage) + 1; }, query: (page: number) => { - return leaderboards.ScoreSaber.queries.lookupGlobalPlayers(page); + return scoresaberService.lookupPlayers(page); }, }, Country: { @@ -51,10 +51,7 @@ const miniVariants: Variants = { return Math.floor((player.countryRank - 1) / itemsPerPage) + 1; }, query: (page: number, country: string) => { - return leaderboards.ScoreSaber.queries.lookupGlobalPlayersByCountry( - page, - country, - ); + return scoresaberService.lookupPlayersByCountry(page, country); }, }, };