Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
delbaoliveira committed Oct 9, 2023
1 parent 56a4199 commit efe0cd1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions dashboard/15-final/app/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,27 @@ export const generateYAxis = (revenue: Revenue[]) => {
};

export const generatePagination = (currentPage: number, totalPages: number) => {
// If the total number of pages is 7 or less,
// display all pages without any ellipsis.
if (totalPages <= 7) {
return Array.from({ length: totalPages }, (_, i) => i + 1);
}

// If the current page is among the first 3 pages,
// show the first 3, an ellipsis, and the last 2 pages.
if (currentPage <= 3) {
return [1, 2, 3, '...', totalPages - 1, totalPages];
}

// If the current page is among the last 3 pages,
// show the first 2, an ellipsis, and the last 3 pages.
if (currentPage >= totalPages - 2) {
return [1, 2, '...', totalPages - 2, totalPages - 1, totalPages];
}

// If the current page is somewhere in the middle,
// show the first page, an ellipsis, the current page and its neighbors,
// another ellipsis, and the last page.
return [
1,
'...',
Expand Down

0 comments on commit efe0cd1

Please sign in to comment.