Skip to content

Commit 4efb46f

Browse files
committed
feat: update pagination logic to support mobile-first design and dynamic page visibility
1 parent d35aa68 commit 4efb46f

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/components/PaginatedNavigation.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,29 @@ export const PaginatedNavigation = ({
2222
const generatePages = () => {
2323
const pages: (number | 'ellipsis')[] = [];
2424

25-
if (totalPages <= 7) {
26-
// Show all pages if 7 or fewer
25+
// Mobile-first approach: show fewer pages on small screens
26+
const isMobile = typeof window !== 'undefined' && window.innerWidth < 640;
27+
const maxVisiblePages = isMobile ? 3 : 7;
28+
29+
if (totalPages <= maxVisiblePages) {
30+
// Show all pages if within limit
2731
for (let i = 1; i <= totalPages; i++) {
2832
pages.push(i);
2933
}
34+
} else if (isMobile) {
35+
// Mobile: simplified pagination - only show current and neighbors
36+
if (currentPage === 1) {
37+
// At start: 1 2 ... last
38+
pages.push(1, 2, 'ellipsis', totalPages);
39+
} else if (currentPage === totalPages) {
40+
// At end: 1 ... (last-1) last
41+
pages.push(1, 'ellipsis', totalPages - 1, totalPages);
42+
} else {
43+
// Middle: 1 ... current ... last
44+
pages.push(1, 'ellipsis', currentPage, 'ellipsis', totalPages);
45+
}
3046
} else {
31-
// Always show first page
47+
// Desktop: full pagination logic
3248
pages.push(1);
3349

3450
if (currentPage <= 3) {

0 commit comments

Comments
 (0)