Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions frontend/js/leaderboard/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ function setupPaginationListeners() {
});

document.getElementById("next-page-btn")?.addEventListener("click", () => {
const totalPages = Math.ceil(
leaderboardData[activeDatasetType].length / itemsPerPage,
);
const totalPages = window.totalPages || 1;

if (currentPage < totalPages) {
currentPage++;
Expand All @@ -25,6 +23,13 @@ function renderPagination(totalItems) {

if (!pageNumbers) return;

const isSearching =
typeof currentSearchTerm !== "undefined" && currentSearchTerm.length > 0;
if (isSearching) {
pageNumbers.innerHTML = "";
return;
}

const totalPages = Math.ceil(totalItems / itemsPerPage);
pageNumbers.innerHTML = "";

Expand Down
3 changes: 3 additions & 0 deletions frontend/js/leaderboard/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function setupSearchListeners() {

clearBtn.style.display = e.target.value.trim() !== "" ? "flex" : "none";

currentPage = 1;
applyFiltersAndRender();
}, 300),
);
Expand All @@ -29,6 +30,7 @@ function setupSearchListeners() {
clearBtn.style.display = "none";

searchInput.focus();
currentPage = 1;
applyFiltersAndRender();
});

Expand All @@ -53,6 +55,7 @@ function setupSearchListeners() {
currentSearchTerm = "";
clearBtn.style.display = "none";
searchInput.blur();
currentPage = 1;
applyFiltersAndRender();
}
});
Expand Down
80 changes: 53 additions & 27 deletions frontend/leaderboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -556,37 +556,63 @@ <h1 class="page-title">Leaderboard</h1>
(user) => user && !zeroScoreUserIds.has(user.id),
);

const totalPages = Math.ceil(renderableData.length / itemsPerPage) || 1;
document.getElementById("prev-page-btn").disabled = currentPage === 1;
document.getElementById("next-page-btn").disabled =
currentPage === totalPages;

const isSearching = currentSearchTerm.length > 0;
const statsEl = document.getElementById("leaderboard-stats");

const startRow =
renderableData.length === 0
? 0
: (currentPage - 1) * itemsPerPage + 1;

const endRow = Math.min(
currentPage * itemsPerPage,
renderableData.length,
);
if (isSearching) {
document.getElementById("prev-page-btn").disabled = true;
document.getElementById("next-page-btn").disabled = true;
window.totalPages = 1;

const totalMatched = filteredData.length;
const startRow = totalMatched === 0 ? 0 : 1;
const endRow = totalMatched;

statsEl.innerHTML = `
<div style="
text-align:center;
color:var(--text-dim);
margin-bottom:1rem;
font-family:'Fira Code', monospace;
">
Total Users: ${totalMatched}
| Showing: ${startRow}-${endRow}
| Page: 1/1
</div>
`;
} else {
const totalPages =
Math.ceil(renderableData.length / itemsPerPage) || 1;
window.totalPages = totalPages;
document.getElementById("prev-page-btn").disabled = currentPage === 1;
document.getElementById("next-page-btn").disabled =
currentPage === totalPages;

const startRow =
renderableData.length === 0
? 0
: (currentPage - 1) * itemsPerPage + 1;

const endRow = Math.min(
currentPage * itemsPerPage,
renderableData.length,
);

statsEl.innerHTML = `
<div style="
text-align:center;
color:var(--text-dim);
margin-bottom:1rem;
font-family:'Fira Code', monospace;
">
Total Users: ${filteredData.length}
| Showing: ${startRow}-${endRow}
| Page: ${currentPage}/${totalPages}
</div>
`;
statsEl.innerHTML = `
<div style="
text-align:center;
color:var(--text-dim);
margin-bottom:1rem;
font-family:'Fira Code', monospace;
">
Total Users: ${renderableData.length}
| Showing: ${startRow}-${endRow}
| Page: ${currentPage}/${totalPages}
</div>
`;
}

renderLeaderboard(filteredData, zeroScoreUserIds, totalPages);
renderLeaderboard(filteredData, zeroScoreUserIds, window.totalPages);
}

function renderLeaderboard(data, zeroScoreUserIds, totalPages) {
Expand Down
Loading