Show pagination
This commit is contained in:
+11
-6
@@ -4,13 +4,16 @@ import Pagination from '@/components/Pagination';
|
|||||||
import Property from '@/models/Property';
|
import Property from '@/models/Property';
|
||||||
import connectDB from '@/config/database';
|
import connectDB from '@/config/database';
|
||||||
|
|
||||||
const PropertiesPage = async ({ searchParams: { pageSize = 3, page = 1 } }) => {
|
const PropertiesPage = async ({ searchParams: { pageSize = 9, page = 1 } }) => {
|
||||||
await connectDB();
|
await connectDB();
|
||||||
const skip = (page - 1) * pageSize;
|
const skip = (page - 1) * pageSize;
|
||||||
|
|
||||||
const total = await Property.countDocuments({});
|
const total = await Property.countDocuments({});
|
||||||
const properties = await Property.find({}).skip(skip).limit(pageSize);
|
const properties = await Property.find({}).skip(skip).limit(pageSize);
|
||||||
|
|
||||||
|
// Calculate if pagination is needed
|
||||||
|
const showPagination = total > pageSize;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<section className='bg-blue-700 py-4'>
|
<section className='bg-blue-700 py-4'>
|
||||||
@@ -30,11 +33,13 @@ const PropertiesPage = async ({ searchParams: { pageSize = 3, page = 1 } }) => {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<Pagination
|
{showPagination && (
|
||||||
page={parseInt(page)}
|
<Pagination
|
||||||
pageSize={parseInt(pageSize)}
|
page={parseInt(page)}
|
||||||
totalItems={total}
|
pageSize={parseInt(pageSize)}
|
||||||
/>
|
totalItems={total}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user