Skip to content

Commit

Permalink
[Assistnats] Fix pagination numTotalPages (huggingface#780)
Browse files Browse the repository at this point in the history
* [Assistnats] Fix pagination numTotalPages

* morereactivity
  • Loading branch information
Mishig authored Feb 5, 2024
1 parent 3890de7 commit 2468399
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib/components/Pagination.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
const ELLIPSIS_IDX = -1 as const;
const numTotalPages = Math.ceil(numTotalItems / numItemsPerPage);
$: numTotalPages = Math.ceil(numTotalItems / numItemsPerPage);
$: pageIndex = parseInt($page.url.searchParams.get("p") ?? "0");
$: pageIndexes = getPageIndexes(pageIndex);
$: pageIndexes = getPageIndexes(pageIndex, numTotalPages);
function getHref(pageIdx: number) {
const newUrl = new URL($page.url);
newUrl.searchParams.set("p", pageIdx.toString());
return newUrl.toString();
}
function getPageIndexes(pageIdx: number) {
function getPageIndexes(pageIdx: number, nTotalPages: number) {
let pageIdxs: number[] = [];
const NUM_EXTRA_BUTTONS = 2; // The number of page links to show on either side of the current page link.
const minIdx = 0;
const maxIdx = numTotalPages - 1;
const maxIdx = nTotalPages - 1;
pageIdxs = [pageIdx];
Expand Down

0 comments on commit 2468399

Please sign in to comment.