From 5c26a429e87eae4ce6cbf8de8c71f8b4b0035673 Mon Sep 17 00:00:00 2001 From: jainish koladiya <155936377+jainish2222@users.noreply.github.com> Date: Tue, 27 May 2025 22:52:35 +0530 Subject: [PATCH] pagination page.tsx If the number of cards is greater than 10, display "Next" and "Previous" buttons to navigate through the remaining cards in sets of 10. --- app/companions/page.tsx | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/app/companions/page.tsx b/app/companions/page.tsx index c0801c4e..111da76a 100644 --- a/app/companions/page.tsx +++ b/app/companions/page.tsx @@ -3,13 +3,16 @@ import CompanionCard from "@/components/CompanionCard"; import {getSubjectColor} from "@/lib/utils"; import SearchInput from "@/components/SearchInput"; import SubjectFilter from "@/components/SubjectFilter"; +import Link from "next/link"; const CompanionsLibrary = async ({ searchParams }: SearchParams) => { const filters = await searchParams; - const subject = filters.subject ? filters.subject : ''; - const topic = filters.topic ? filters.topic : ''; + const subject = filters.subject ?? ''; + const topic = filters.topic ?? ''; + const page = parseInt(filters.page) || 1; + const limit = 9; - const companions = await getAllCompanions({ subject, topic }); + const companions = await getAllCompanions({ subject, topic, page, limit }); return (
@@ -20,6 +23,7 @@ const CompanionsLibrary = async ({ searchParams }: SearchParams) => { +
{companions.map((companion) => ( { /> ))}
+ +
+ {page > 1 && ( + + ← Previous + + )} + {companions.length === limit && ( + + Next → + + )} +
- ) + ); } + export default CompanionsLibrary