Next/Previous => Older/Newer

This commit is contained in:
Ian Philips 2022-07-19 14:16:20 -06:00
parent b6c8390a46
commit 6dcad6225b
2 changed files with 23 additions and 9 deletions

View File

@ -4,8 +4,18 @@ export function Pagination(props: {
totalItems: number totalItems: number
setPage: (page: number) => void setPage: (page: number) => void
scrollToTop?: boolean scrollToTop?: boolean
nextTitle?: string
prevTitle?: string
}) { }) {
const { page, itemsPerPage, totalItems, setPage, scrollToTop } = props const {
page,
itemsPerPage,
totalItems,
setPage,
scrollToTop,
nextTitle,
prevTitle,
} = props
const maxPage = Math.ceil(totalItems / itemsPerPage) - 1 const maxPage = Math.ceil(totalItems / itemsPerPage) - 1
@ -25,19 +35,21 @@ export function Pagination(props: {
</p> </p>
</div> </div>
<div className="flex flex-1 justify-between sm:justify-end"> <div className="flex flex-1 justify-between sm:justify-end">
<a {page > 0 && (
href={scrollToTop ? '#' : undefined} <a
className="relative inline-flex cursor-pointer select-none items-center rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50" href={scrollToTop ? '#' : undefined}
onClick={() => page > 0 && setPage(page - 1)} className="relative inline-flex cursor-pointer select-none items-center rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50"
> onClick={() => page > 0 && setPage(page - 1)}
Previous >
</a> {prevTitle ?? 'Previous'}
</a>
)}
<a <a
href={scrollToTop ? '#' : undefined} href={scrollToTop ? '#' : undefined}
className="relative ml-3 inline-flex cursor-pointer select-none items-center rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50" className="relative ml-3 inline-flex cursor-pointer select-none items-center rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50"
onClick={() => page < maxPage && setPage(page + 1)} onClick={() => page < maxPage && setPage(page + 1)}
> >
Next {nextTitle ?? 'Next'}
</a> </a>
</div> </div>
</nav> </nav>

View File

@ -205,6 +205,8 @@ function NotificationsList(props: {
totalItems={allGroupedNotifications.length} totalItems={allGroupedNotifications.length}
setPage={setPage} setPage={setPage}
scrollToTop scrollToTop
nextTitle={'Older'}
prevTitle={'Newer'}
/> />
)} )}
</div> </div>