Skip to content

Commit aaa519b

Browse files
authored
fix(leaderboards): user button navigating to the wrong page (@fehmer) (monkeytypegame#6334)
1 parent e4baede commit aaa519b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

frontend/src/ts/pages/leaderboards.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@ function updateJumpButtons(): void {
435435

436436
if (totalPages <= 1) {
437437
el.find("button").addClass("disabled");
438-
return;
439438
} else {
440439
el.find("button").removeClass("disabled");
441440
}
@@ -448,12 +447,17 @@ function updateJumpButtons(): void {
448447
el.find("button[data-action='firstPage']").removeClass("disabled");
449448
}
450449

451-
if (isAuthenticated() && state.userData) {
452-
const userPage = Math.floor(state.userData.rank / state.pageSize);
453-
if (state.page === userPage) {
454-
el.find("button[data-action='userPage']").addClass("disabled");
450+
if (isAuthenticated()) {
451+
const userButton = el.find("button[data-action='userPage']");
452+
if (!state.userData) {
453+
userButton.addClass("disabled");
455454
} else {
456-
el.find("button[data-action='userPage']").removeClass("disabled");
455+
const userPage = Math.floor((state.userData.rank - 1) / state.pageSize);
456+
if (state.page === userPage) {
457+
userButton.addClass("disabled");
458+
} else {
459+
userButton.removeClass("disabled");
460+
}
457461
}
458462
}
459463

@@ -1110,7 +1114,7 @@ function handleJumpButton(action: string, page?: number): void {
11101114
const rank = state.userData?.rank;
11111115
if (rank) {
11121116
// - 1 to make sure position 50 with page size 50 is on the first page (page 0)
1113-
const page = Math.floor(rank - 1 / state.pageSize);
1117+
const page = Math.floor((rank - 1) / state.pageSize);
11141118

11151119
if (state.page === page) {
11161120
return;

0 commit comments

Comments
 (0)