fix the url randomly switching to a leaderboard
All checks were successful
Deploy Website / docker (ubuntu-latest) (push) Successful in 2m10s

This commit is contained in:
Lee 2024-10-19 17:33:47 +01:00
parent 2df95d140a
commit 1e8c38eb26
2 changed files with 12 additions and 2 deletions

View File

@ -25,6 +25,7 @@ type LeaderboardScoresProps = {
showDifficulties?: boolean;
isLeaderboardPage?: boolean;
leaderboardChanged?: (id: number) => void;
disableUrlChanging?: boolean;
};
export default function LeaderboardScores({
@ -34,6 +35,7 @@ export default function LeaderboardScores({
showDifficulties,
isLeaderboardPage,
leaderboardChanged,
disableUrlChanging,
}: LeaderboardScoresProps) {
if (!initialPage) {
initialPage = 1;
@ -115,9 +117,13 @@ export default function LeaderboardScores({
}, [currentPage, topOfScoresRef, shouldFetch]);
useEffect(() => {
if (disableUrlChanging) {
return;
}
// Update the URL
window.history.replaceState(null, "", `/leaderboard/${selectedLeaderboardId}/${currentPage}`);
}, [selectedLeaderboardId, currentPage]);
}, [selectedLeaderboardId, currentPage, disableUrlChanging]);
if (currentScores === undefined) {
return undefined;

View File

@ -103,7 +103,11 @@ export default function Score({ leaderboard, beatSaverMap, score, settings }: Pr
animate={{ opacity: 1, y: 0 }}
className="w-full mt-2"
>
<LeaderboardScores initialPage={getPageFromRank(score.rank, 12)} leaderboard={leaderboard} />
<LeaderboardScores
initialPage={getPageFromRank(score.rank, 12)}
leaderboard={leaderboard}
disableUrlChanging
/>
</motion.div>
)}
</div>