Skip to content

Commit a591305

Browse files
previous/next button is now working
1 parent a06e910 commit a591305

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/features/product/components/ProductList.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -443,21 +443,22 @@ function ProductGrid({ products }) {
443443
}
444444

445445
function Pagination({ page, setPage, handlePage, totalItems }) {
446+
const totalPages = Math.ceil(totalItems / ITEMS_PER_PAGE);
446447
return (
447448
<div className="flex items-center justify-between border-t border-gray-200 bg-white px-4 py-3 sm:px-6">
448449
<div className="flex flex-1 justify-between sm:hidden">
449450
<a
450-
href="#"
451+
onClick={() => handlePage(page > 1 ? page - 1 : page)}
451452
className="relative inline-flex 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"
452453
>
453454
Previous
454455
</a>
455-
<a
456-
href="#"
456+
<div
457+
onClick={() => handlePage(page < totalPages ? page + 1 : page)}
457458
className="relative ml-3 inline-flex 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"
458459
>
459460
Next
460-
</a>
461+
</div>
461462
</div>
462463
<div className="hidden sm:flex sm:flex-1 sm:items-center sm:justify-between">
463464
<div>
@@ -481,15 +482,15 @@ function Pagination({ page, setPage, handlePage, totalItems }) {
481482
className="isolate inline-flex -space-x-px rounded-md shadow-sm"
482483
aria-label="Pagination"
483484
>
484-
<a
485-
href="#"
485+
<div
486+
onClick={() => handlePage(page > 1 ? page - 1 : page)}
486487
className="relative inline-flex items-center rounded-l-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0"
487488
>
488489
<span className="sr-only">Previous</span>
489490
<ChevronLeftIcon className="h-5 w-5" aria-hidden="true" />
490-
</a>
491+
</div>
491492
{/* Current: "z-10 bg-indigo-600 text-white focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600", Default: "text-gray-900 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:outline-offset-0" */}
492-
{Array.from({ length: Math.ceil(totalItems / ITEMS_PER_PAGE) }).map(
493+
{Array.from({ length: totalPages }).map(
493494
//extracting all the indexes of array
494495
(el, index) => (
495496
<div
@@ -506,13 +507,13 @@ function Pagination({ page, setPage, handlePage, totalItems }) {
506507
)
507508
)}
508509

509-
<a
510-
href="#"
510+
<div
511+
onClick={() => handlePage(page < totalPages ? page + 1 : page)}
511512
className="relative inline-flex items-center rounded-r-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0"
512513
>
513514
<span className="sr-only">Next</span>
514515
<ChevronRightIcon className="h-5 w-5" aria-hidden="true" />
515-
</a>
516+
</div>
516517
</nav>
517518
</div>
518519
</div>

0 commit comments

Comments
 (0)