diff --git a/src/app/api/quoteList/route.ts b/src/app/api/quoteList/[quote_id]/route.ts similarity index 74% rename from src/app/api/quoteList/route.ts rename to src/app/api/quoteList/[quote_id]/route.ts index c268d15..a6da8d4 100644 --- a/src/app/api/quoteList/route.ts +++ b/src/app/api/quoteList/[quote_id]/route.ts @@ -4,10 +4,13 @@ import prisma from "@/app/lib/prisma"; import { createClient } from "@/app/utils/supabase/server"; import { NextRequest } from "next/server"; -export async function GET(req: NextRequest) { +export async function GET( + req: NextRequest, + { params }: { params: { quote_id: string } } +) { const supabase = createClient(); const user = await supabase.auth.getUser(); - + const quoteNumber = parseInt(params.quote_id); const quotes = user.data.user ? await prisma.user.findUnique({ where: { @@ -20,6 +23,9 @@ export async function GET(req: NextRequest) { }, }) : await prisma.quote.findMany({ + take: 10, + skip: quoteNumber ? 10 : 0, + ...(quoteNumber && { cursor: { id: quoteNumber } }), orderBy: [ { id: "asc", diff --git a/src/app/quote-list/page.tsx b/src/app/quote-list/page.tsx index c557e6b..459b268 100644 --- a/src/app/quote-list/page.tsx +++ b/src/app/quote-list/page.tsx @@ -5,28 +5,28 @@ import { useEffect, useState } from "react"; export default function QuoteList() { const [list, setList] = useState([]); + const [page, setPage] = useState(0); const router = useRouter(); useEffect(() => { - fetch("/api/quoteList") + fetch(`/api/quoteList/${page}`) .then((data) => data.json()) .then((res) => { const { data } = res; setList(data); }); - }, []); - + }, [page]); const handleQuoteClick = (index: number) => { router.push(`/${index}`); }; //TODO: fix the type of the value in map return ( -
-
Quote List
+
+
Quote List
{list.map((value: any, index: number) => { return (
handleQuoteClick(index + 1)} >
@@ -38,6 +38,17 @@ export default function QuoteList() {
); })} +
+ +
{page}
+ +
); }