mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 12:54:38 +03:00
Add index/total count to end of pagination buttons (#490)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Button, ButtonGroup } from "react-bootstrap";
|
import { Button, ButtonGroup } from "react-bootstrap";
|
||||||
|
import { useIntl } from "react-intl";
|
||||||
|
|
||||||
interface IPaginationProps {
|
interface IPaginationProps {
|
||||||
itemsPerPage: number;
|
itemsPerPage: number;
|
||||||
@@ -8,6 +9,13 @@ interface IPaginationProps {
|
|||||||
onChangePage: (page: number) => void;
|
onChangePage: (page: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IPaginationIndexProps {
|
||||||
|
itemsPerPage: number;
|
||||||
|
currentPage: number;
|
||||||
|
totalItems: number;
|
||||||
|
onClick?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
export const Pagination: React.FC<IPaginationProps> = ({
|
export const Pagination: React.FC<IPaginationProps> = ({
|
||||||
itemsPerPage,
|
itemsPerPage,
|
||||||
currentPage,
|
currentPage,
|
||||||
@@ -99,3 +107,19 @@ export const Pagination: React.FC<IPaginationProps> = ({
|
|||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const PaginationIndex: React.FC<IPaginationIndexProps> = ({
|
||||||
|
itemsPerPage,
|
||||||
|
currentPage,
|
||||||
|
totalItems,
|
||||||
|
onClick
|
||||||
|
}) => {
|
||||||
|
const intl = useIntl();
|
||||||
|
|
||||||
|
// Build the pagination index string
|
||||||
|
const firstItemCount:number = Math.min((currentPage-1)*itemsPerPage+1, totalItems);
|
||||||
|
const lastItemCount:number = Math.min(firstItemCount+(itemsPerPage-1), totalItems);
|
||||||
|
const indexText:string = `${intl.formatNumber(firstItemCount)}-${intl.formatNumber(lastItemCount)} of ${intl.formatNumber(totalItems)}`;
|
||||||
|
|
||||||
|
return <span className="filter-container text-muted paginationIndex" onClick={onClick}>{indexText}</span>
|
||||||
|
};
|
||||||
@@ -24,7 +24,7 @@ import {
|
|||||||
} from "src/hooks/LocalForage";
|
} from "src/hooks/LocalForage";
|
||||||
import { LoadingIndicator } from "src/components/Shared";
|
import { LoadingIndicator } from "src/components/Shared";
|
||||||
import { ListFilter } from "src/components/List/ListFilter";
|
import { ListFilter } from "src/components/List/ListFilter";
|
||||||
import { Pagination } from "src/components/List/Pagination";
|
import { Pagination, PaginationIndex } from "src/components/List/Pagination";
|
||||||
import { StashService } from "src/core/StashService";
|
import { StashService } from "src/core/StashService";
|
||||||
import { Criterion } from "src/models/list-filter/criteria/criterion";
|
import { Criterion } from "src/models/list-filter/criteria/criterion";
|
||||||
import { ListFilterModel } from "src/models/list-filter/filter";
|
import { ListFilterModel } from "src/models/list-filter/filter";
|
||||||
@@ -357,6 +357,19 @@ const useList = <QueryResult extends IQueryResult, QueryData extends IDataItem>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function maybeRenderPaginationIndex() {
|
||||||
|
if (!result.loading && !result.error) {
|
||||||
|
return (
|
||||||
|
<PaginationIndex
|
||||||
|
itemsPerPage={filter.itemsPerPage}
|
||||||
|
currentPage={filter.currentPage}
|
||||||
|
totalItems={totalCount}
|
||||||
|
onClick={() => {}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function maybeRenderPagination() {
|
function maybeRenderPagination() {
|
||||||
if (!result.loading && !result.error) {
|
if (!result.loading && !result.error) {
|
||||||
return (
|
return (
|
||||||
@@ -394,6 +407,7 @@ const useList = <QueryResult extends IQueryResult, QueryData extends IDataItem>(
|
|||||||
{(result.loading || !forageInitialised) && <LoadingIndicator />}
|
{(result.loading || !forageInitialised) && <LoadingIndicator />}
|
||||||
{result.error && <h1>{result.error.message}</h1>}
|
{result.error && <h1>{result.error.message}</h1>}
|
||||||
{maybeRenderContent()}
|
{maybeRenderContent()}
|
||||||
|
{maybeRenderPaginationIndex()}
|
||||||
{maybeRenderPagination()}
|
{maybeRenderPagination()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user