From 41aa3ebaaf97484034b148e51adf5873bfec6e70 Mon Sep 17 00:00:00 2001 From: zkldi Date: Fri, 7 Jun 2024 12:46:37 +0100 Subject: [PATCH] fix: this messes up the cache; what the hell? --- .../games/_game/_playtype/ScoresPage.tsx | 47 ++++++++----------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/client/src/app/pages/dashboard/users/games/_game/_playtype/ScoresPage.tsx b/client/src/app/pages/dashboard/users/games/_game/_playtype/ScoresPage.tsx index d34cc10c7..9439f3f3c 100644 --- a/client/src/app/pages/dashboard/users/games/_game/_playtype/ScoresPage.tsx +++ b/client/src/app/pages/dashboard/users/games/_game/_playtype/ScoresPage.tsx @@ -29,6 +29,7 @@ import { import { GamePT, SetState, UGPT } from "types/react"; import usePreferredRanking from "components/util/usePreferredRanking"; import { Col, Form, Row } from "react-bootstrap"; +import useApiQuery from "components/util/query/useApiQuery"; export default function ScoresPage({ reqUser, @@ -135,21 +136,16 @@ function AlgSelector({ } function useFetchPBs(url: string, reqUser: UserDocument) { - const { data, error } = useQuery(url, async () => { - const res = await APIFetchV1<{ - pbs: PBScoreDocument[]; - charts: ChartDocument[]; - songs: SongDocument[]; - }>(url); + const { data, error } = useApiQuery<{ + pbs: PBScoreDocument[]; + charts: ChartDocument[]; + songs: SongDocument[]; + }>(url); - if (!res.success) { - throw res; - } - - return FormatData(res.body.pbs, res.body.songs, res.body.charts, reqUser); - }); - - return { error: error as UnsuccessfulAPIResponse, data }; + return { + error: error as UnsuccessfulAPIResponse, + data: data ? FormatData(data.pbs, data.songs, data.charts, reqUser) : undefined, + }; } function PBsOverview({ @@ -229,21 +225,16 @@ function FormatData< } function useFetchScores(url: string, reqUser: UserDocument) { - const { data, error } = useQuery(url, async () => { - const res = await APIFetchV1<{ - scores: ScoreDocument[]; - charts: ChartDocument[]; - songs: SongDocument[]; - }>(url); + const { data, error } = useApiQuery<{ + scores: ScoreDocument[]; + charts: ChartDocument[]; + songs: SongDocument[]; + }>(url); - if (!res.success) { - throw res; - } - - return FormatData(res.body.scores, res.body.songs, res.body.charts, reqUser); - }); - - return { error: error as UnsuccessfulAPIResponse, data }; + return { + error: error as UnsuccessfulAPIResponse, + data: data ? FormatData(data.scores, data.songs, data.charts, reqUser) : undefined, + }; } function PBsSearch({