fix(ssr): fix pagination
All checks were successful
deploy / deploy (push) Successful in 1m1s

This commit is contained in:
Lee 2023-11-08 11:58:36 +00:00
parent 3b2e726fa1
commit 662999f65b
2 changed files with 18 additions and 2 deletions

@ -71,6 +71,7 @@ export default function GlobalRanking({
<Pagination <Pagination
currentPage={pageInfo.page} currentPage={pageInfo.page}
totalPages={pageInfo.totalPages} totalPages={pageInfo.totalPages}
useHref
/> />
</div> </div>
</div> </div>

@ -47,10 +47,16 @@ export default function Scores({
sortType: initalSortType, sortType: initalSortType,
scores: initalScores ? initalScores : [], scores: initalScores ? initalScores : [],
}); });
const [changedPage, setChangedPage] = useState(false);
const updateScoresPage = useCallback( const updateScoresPage = useCallback(
(sortType: SortType, page: any) => { (sortType: SortType, page: any) => {
if (page == initalPage && sortType == initalSortType && initalScores) { if (
page == initalPage &&
sortType == initalSortType &&
initalScores &&
!changedPage
) {
console.log("Already loaded scores, not fetching"); console.log("Already loaded scores, not fetching");
return; return;
} }
@ -76,12 +82,21 @@ export default function Scores({
"", "",
`/player/${playerId}/${sortType.value}/${page}`, `/player/${playerId}/${sortType.value}/${page}`,
); );
setChangedPage(true);
console.log(`Switched page to ${page} with sort ${sortType.value}`); console.log(`Switched page to ${page} with sort ${sortType.value}`);
}, },
); );
}, },
[initalPage, initalScores, initalSortType, playerId, scores, settingsStore], [
changedPage,
initalPage,
initalScores,
initalSortType,
playerId,
scores,
settingsStore,
],
); );
useEffect(() => { useEffect(() => {