Skip to content

Commit

Permalink
SOV-4302: add pagination page limit (#959)
Browse files Browse the repository at this point in the history
* feat: add pagination page limit

* Create spicy-eagles-sneeze.md
  • Loading branch information
rick23p authored Jul 23, 2024
1 parent 9ed0c28 commit 8d41bc7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changeset/spicy-eagles-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"frontend": patch
"@sovryn/ui": patch
---

SOV-4302: add pagination page limit
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { translations } from '../../../../../locales/i18n';
export const DATA_ENDPOINT_URL =
'https://season2-spice-points-bucket.s3.us-east-2.amazonaws.com/latest_Season2_Spice_distributed.json';

export const PAGE_SIZE = 80;
export const PAGE_SIZE = 50;

export const COLUMNS_CONFIG = (isSingleUser: boolean = false) => [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const LeaderboardPointsSeason2: FC = () => {
itemsPerPage={PAGE_SIZE}
isNextButtonDisabled={isNextButtonDisabled}
dataAttribute="leaderboard-points-users-pagination-season-2"
pageLimit={10}
/>
</div>
</div>
Expand Down
39 changes: 28 additions & 11 deletions packages/ui/src/2_molecules/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type PaginationProps = {
hideFirstPageButton?: boolean;
hideLastPageButton?: boolean;
isNextButtonDisabled?: boolean;
pageLimit?: number;
};

const DEFAULT_ITEMS_PER_PAGE = 5;
Expand All @@ -32,6 +33,7 @@ export const Pagination: FC<PaginationProps> = ({
hideFirstPageButton,
hideLastPageButton,
isNextButtonDisabled,
pageLimit,
}) => {
const {
isNextButtonDisabled: nextButtonDisabled,
Expand Down Expand Up @@ -68,17 +70,32 @@ export const Pagination: FC<PaginationProps> = ({
/>
{totalPages !== undefined ? (
<>
{new Array(totalPages).fill(0).map((_item, index) => (
<button
key={index}
className={classNames(styles.page, {
[styles.active]: index === page,
})}
onClick={() => onChange(index)}
>
{index + 1}
</button>
))}
{new Array(
pageLimit && pageLimit < totalPages ? pageLimit : totalPages,
)
.fill(0)
.map((_item, index) => {
let start = pageLimit
? Math.max(Math.floor(page - pageLimit / 2), 0)
: 0;

if (pageLimit && start + pageLimit > totalPages) {
start = totalPages - pageLimit;
}
const pageNumber = index + start;

return (
<button
key={pageNumber}
className={classNames(styles.page, {
[styles.active]: pageNumber === page,
})}
onClick={() => onChange(pageNumber)}
>
{pageNumber + 1}
</button>
);
})}
</>
) : (
<button className={classNames(styles.page, styles.active)}>
Expand Down

0 comments on commit 8d41bc7

Please sign in to comment.