Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit efe0cd1

Browse files
committedOct 9, 2023
Add comments
1 parent 56a4199 commit efe0cd1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
 

‎dashboard/15-final/app/lib/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,27 @@ export const generateYAxis = (revenue: Revenue[]) => {
3636
};
3737

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

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

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

57+
// If the current page is somewhere in the middle,
58+
// show the first page, an ellipsis, the current page and its neighbors,
59+
// another ellipsis, and the last page.
5160
return [
5261
1,
5362
'...',

0 commit comments

Comments
 (0)