From 6d093c327f6df99c6b5d4ad0a23180df3f9307b1 Mon Sep 17 00:00:00 2001 From: ngc2207 Date: Tue, 12 Nov 2024 16:01:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=89=87=E6=AE=B5=E7=BC=96=E8=BE=91=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BB=A3=E7=A0=81=E7=89=87=E6=AE=B5=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E8=A1=A8=E5=8D=95=E5=AE=A2=E6=88=B7=E7=AB=AF=E7=BB=84?= =?UTF-8?q?=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/snippets/[id]/edit/page.tsx | 17 ++++++++++++++++- src/components/snippet-edit-form.tsx | 11 +++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/components/snippet-edit-form.tsx diff --git a/src/app/snippets/[id]/edit/page.tsx b/src/app/snippets/[id]/edit/page.tsx index 9f16eff..1608823 100644 --- a/src/app/snippets/[id]/edit/page.tsx +++ b/src/app/snippets/[id]/edit/page.tsx @@ -1,3 +1,7 @@ +import { db } from "@/db"; +import { notFound } from "next/navigation"; +import SnippetEditForm from "@/components/snippet-edit-form"; + interface SnippetEditPageProps { params: Promise<{ id: string; @@ -7,5 +11,16 @@ interface SnippetEditPageProps { export default async function SnippetEditPage(props: SnippetEditPageProps) { const params = await props.params; const id = parseInt(params.id); - return
Editing snippet with id {id}
; + const snippet = await db.snippet.findFirst({ + where: { id }, + }); + + if (!snippet) { + return notFound(); + } + return ( +
+ +
+ ); } diff --git a/src/components/snippet-edit-form.tsx b/src/components/snippet-edit-form.tsx new file mode 100644 index 0000000..b6ac561 --- /dev/null +++ b/src/components/snippet-edit-form.tsx @@ -0,0 +1,11 @@ +"use client"; + +import { Snippet } from "@prisma/client"; + +interface SnippetEditFormProps { + snippet: Snippet; +} + +export default function SnippetEditForm({ snippet }: SnippetEditFormProps) { + return
Client component has snippet with title {snippet.title}
; +}