mirror of
https://github.com/stashapp/stash.git
synced 2025-12-14 20:33:16 +01:00
Show page numbers on low page count (#5206)
Shows individual page numbers instead of the page count selector when pages < 4.
This commit is contained in:
parent
7b064ac99e
commit
4e9925fd3f
1 changed files with 28 additions and 8 deletions
|
|
@ -8,7 +8,7 @@ import {
|
||||||
Overlay,
|
Overlay,
|
||||||
Popover,
|
Popover,
|
||||||
} from "react-bootstrap";
|
} from "react-bootstrap";
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, FormattedNumber, useIntl } from "react-intl";
|
||||||
import useFocus from "src/utils/focus";
|
import useFocus from "src/utils/focus";
|
||||||
import { Icon } from "../Shared/Icon";
|
import { Icon } from "../Shared/Icon";
|
||||||
import { faCheck, faChevronDown } from "@fortawesome/free-solid-svg-icons";
|
import { faCheck, faChevronDown } from "@fortawesome/free-solid-svg-icons";
|
||||||
|
|
@ -143,6 +143,8 @@ interface IPaginationIndexProps {
|
||||||
metadataByline?: React.ReactNode;
|
metadataByline?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const minPagesForCompact = 4;
|
||||||
|
|
||||||
export const Pagination: React.FC<IPaginationProps> = ({
|
export const Pagination: React.FC<IPaginationProps> = ({
|
||||||
itemsPerPage,
|
itemsPerPage,
|
||||||
currentPage,
|
currentPage,
|
||||||
|
|
@ -156,6 +158,30 @@ export const Pagination: React.FC<IPaginationProps> = ({
|
||||||
[totalItems, itemsPerPage]
|
[totalItems, itemsPerPage]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const pageButtons = useMemo(() => {
|
||||||
|
if (totalPages >= minPagesForCompact)
|
||||||
|
return (
|
||||||
|
<PageCount
|
||||||
|
totalPages={totalPages}
|
||||||
|
currentPage={currentPage}
|
||||||
|
onChangePage={onChangePage}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
const pages = [...Array(totalPages).keys()].map((i) => i + 1);
|
||||||
|
|
||||||
|
return pages.map((page: number) => (
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
key={page}
|
||||||
|
active={currentPage === page}
|
||||||
|
onClick={() => onChangePage(page)}
|
||||||
|
>
|
||||||
|
<FormattedNumber value={page} />
|
||||||
|
</Button>
|
||||||
|
));
|
||||||
|
}, [totalPages, currentPage, onChangePage]);
|
||||||
|
|
||||||
if (totalPages <= 1) return <div />;
|
if (totalPages <= 1) return <div />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -176,13 +202,7 @@ export const Pagination: React.FC<IPaginationProps> = ({
|
||||||
>
|
>
|
||||||
<
|
<
|
||||||
</Button>
|
</Button>
|
||||||
|
{pageButtons}
|
||||||
<PageCount
|
|
||||||
totalPages={totalPages}
|
|
||||||
currentPage={currentPage}
|
|
||||||
onChangePage={onChangePage}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
disabled={currentPage === totalPages}
|
disabled={currentPage === totalPages}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue