Skip to content

Commit ea75589

Browse files
authored
Merge pull request #463 from Namiiikaze/feat/#393
Add paginated notification search navigation with numbered pages and …
2 parents 6cc343d + 21d3ce0 commit ea75589

1 file changed

Lines changed: 59 additions & 3 deletions

File tree

dashboard/src/pages/NotificationSearchPage.tsx

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,28 @@ export function NotificationSearchPage() {
203203

204204
const totalPages = response ? response.totalPages : 0;
205205

206+
const getVisiblePages = () => {
207+
if (totalPages <= 1) return [];
208+
209+
const pages: number[] = [];
210+
const maxVisible = 5;
211+
let startPage = Math.max(1, page - Math.floor(maxVisible / 2));
212+
let endPage = startPage + maxVisible - 1;
213+
214+
if (endPage > totalPages) {
215+
endPage = totalPages;
216+
startPage = Math.max(1, endPage - maxVisible + 1);
217+
}
218+
219+
for (let pageNumber = startPage; pageNumber <= endPage; pageNumber += 1) {
220+
pages.push(pageNumber);
221+
}
222+
223+
return pages;
224+
};
225+
226+
const visiblePages = getVisiblePages();
227+
206228
return (
207229
<main className="notif-search-page">
208230
<header className="notif-search-page__header">
@@ -431,6 +453,15 @@ export function NotificationSearchPage() {
431453

432454
{totalPages > 1 && (
433455
<nav className="notif-search-page__pagination" aria-label="Pagination">
456+
<button
457+
type="button"
458+
className="pagination__btn"
459+
disabled={page === 1}
460+
onClick={() => setPage(1)}
461+
aria-label="First page"
462+
>
463+
«
464+
</button>
434465
<button
435466
type="button"
436467
className="pagination__btn"
@@ -440,9 +471,22 @@ export function NotificationSearchPage() {
440471
>
441472
← Previous
442473
</button>
443-
<span className="pagination__info">
444-
Page {page} of {totalPages}
445-
</span>
474+
475+
<div className="pagination__pages" role="list" aria-label="Page numbers">
476+
{visiblePages.map((pageNumber) => (
477+
<button
478+
key={pageNumber}
479+
type="button"
480+
className="pagination__page-btn"
481+
onClick={() => setPage(pageNumber)}
482+
aria-current={pageNumber === page ? 'page' : undefined}
483+
aria-label={`Page ${pageNumber}`}
484+
>
485+
{pageNumber}
486+
</button>
487+
))}
488+
</div>
489+
446490
<button
447491
type="button"
448492
className="pagination__btn"
@@ -452,6 +496,18 @@ export function NotificationSearchPage() {
452496
>
453497
Next →
454498
</button>
499+
<button
500+
type="button"
501+
className="pagination__btn"
502+
disabled={page >= totalPages}
503+
onClick={() => setPage(totalPages)}
504+
aria-label="Last page"
505+
>
506+
»
507+
</button>
508+
<span className="pagination__info">
509+
Page {page} of {totalPages}
510+
</span>
455511
</nav>
456512
)}
457513
</>

0 commit comments

Comments
 (0)