From fada26f8a387b07db2a5123cdb6507d536914e82 Mon Sep 17 00:00:00 2001 From: Brad Traversy Date: Mon, 15 Jul 2024 12:36:36 -0400 Subject: [PATCH] Pagination component --- _theme_files/properties.html | 48 ++++++------------------------------ app/properties/page.jsx | 6 +++++ components/Pagination.jsx | 32 ++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 40 deletions(-) create mode 100644 components/Pagination.jsx diff --git a/_theme_files/properties.html b/_theme_files/properties.html index 2ec96ab..9acfa1f 100644 --- a/_theme_files/properties.html +++ b/_theme_files/properties.html @@ -616,48 +616,16 @@ -
- + + Next +
diff --git a/app/properties/page.jsx b/app/properties/page.jsx index 34bd4c0..a58b447 100644 --- a/app/properties/page.jsx +++ b/app/properties/page.jsx @@ -1,5 +1,6 @@ import PropertyCard from '@/components/PropertyCard'; import PropertySearchForm from '@/components/PropertySearchForm'; +import Pagination from '@/components/Pagination'; import Property from '@/models/Property'; import connectDB from '@/config/database'; @@ -29,6 +30,11 @@ const PropertiesPage = async ({ searchParams: { pageSize = 3, page = 1 } }) => { ))} )} + diff --git a/components/Pagination.jsx b/components/Pagination.jsx new file mode 100644 index 0000000..8baa22e --- /dev/null +++ b/components/Pagination.jsx @@ -0,0 +1,32 @@ +import Link from 'next/link'; + +const Pagination = ({ page, pageSize, totalItems }) => { + const totalPages = Math.ceil(totalItems / pageSize); + return ( +
+ {page > 1 ? ( + + Previous + + ) : null} + + + {' '} + Page {page} of {totalPages} + + + {page < totalPages ? ( + + Next + + ) : null} +
+ ); +}; +export default Pagination;