Skip to content

Commit

Permalink
fix(Pagination): remove constant
Browse files Browse the repository at this point in the history
  • Loading branch information
maeshchenko committed Jan 9, 2024
1 parent 3531a64 commit 585e1a2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
5 changes: 1 addition & 4 deletions src/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import {getResultPage, getResultTotal} from './utils';
import './Pagination.scss';

const b = blockNew('pagination');
const DEFAULT_TOTAL = 1;
const DEFAULT_PAGE = 1;

export const Pagination = ({
page,
Expand All @@ -38,12 +36,11 @@ export const Pagination = ({
const size = mobile ? 'l' : 'm';
const compact = mobile ? true : propCompact;

const resultTotal = getResultTotal(total, DEFAULT_TOTAL);
const resultTotal = getResultTotal(total);
const resultPage = getResultPage({
page,
total: resultTotal,
pageSize,
defaultPage: DEFAULT_PAGE,
});

const {items, numberOfPages} = usePagination({
Expand Down
8 changes: 3 additions & 5 deletions src/components/Pagination/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,20 @@ export function getNumberOfPages(pageSize: number, total = 0) {
return Math.floor((total - 1) / pageSize) + 1;
}

export function getResultTotal(total: number | undefined, defaultTotal: number) {
return total === undefined || total > 0 ? total : defaultTotal;
export function getResultTotal(total: number | undefined) {
return total === undefined || total > 0 ? total : 1;
}

export function getResultPage({
page,
total,
pageSize,
defaultPage,
}: {
page: number;
total: number | undefined;
pageSize: number;
defaultPage: number;
}) {
return page > 0 && (total === undefined || page <= getNumberOfPages(pageSize, total))
? page
: defaultPage;
: 1;
}

0 comments on commit 585e1a2

Please sign in to comment.