Skip to content

Commit

Permalink
Widget pagination: space and next page
Browse files Browse the repository at this point in the history
  • Loading branch information
timendum committed Sep 20, 2024
1 parent 4279278 commit 32793e2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions app/fportal/components/widgetPagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function WidgetPagination({ pag, oldest, setContinuation }: Widge
let disabled = newPage === pag.length - 1;
let text = "";
let tooltip: string | undefined = "Go to page " + text;
let target: string = pag[pag.length - 1];
let target = pag[pag.length - 1];
if (newPage === "-") {
text = "<";
tooltip = "Previous page";
Expand All @@ -26,8 +26,6 @@ export default function WidgetPagination({ pag, oldest, setContinuation }: Widge
text = ">";
tooltip = "Next page";
target = oldest;
} else if (newPage === pag.length) {
target = oldest;
} else if (newPage === "…" || newPage === "-…") {
text = "…";
tooltip = undefined;
Expand All @@ -39,6 +37,12 @@ export default function WidgetPagination({ pag, oldest, setContinuation }: Widge
} else {
text = String(newPage + 1);
target = pag[newPage];
tooltip = "Go to page " + text;
if (newPage === pag.length) {
target = oldest;
} else if (newPage > pag.length) {
throw new Error("Page too big");
}
}
let classes = "md:px-1 xl:px-2 btn-primary mx-auto block";
if (newPage === pag.length - 1) {
Expand All @@ -52,6 +56,7 @@ export default function WidgetPagination({ pag, oldest, setContinuation }: Widge
title={tooltip}
className={classes}
disabled={disabled}
about={String(newPage)}
onClick={() => setContinuation(target)}
>
{text}
Expand All @@ -65,12 +70,11 @@ export default function WidgetPagination({ pag, oldest, setContinuation }: Widge
{makeButton("-")}
{pag.length > 4 && makeButton(0)}
{pag.length > 4 && makeButton("-…")}
{(pag.length > 4 ? [1, 0] : [3, 2, 1, 0])
{(pag.length > 4 ? [2, 1, 0, -1] : [4, 3, 2, 1, 0, -1])
.filter((e) => e < pag.length)
.map((e) => makeButton(pag.length - e - 1))}
{makeButton(pag.length)}
{makeButton("…")}
{[4, 3, 2, 1].filter((e) => e > pag.length).map((e) => makeButton(-e))}
{[5, 4, 3, 2, 1].filter((e) => e > pag.length).map((e) => makeButton(-e))}
{makeButton("+")}
</ul>
</nav>
Expand Down

0 comments on commit 32793e2

Please sign in to comment.