feat: 实现代码片段编辑功能,添加代码片段编辑表单客户端组建

This commit is contained in:
ngc2207 2024-11-12 16:01:37 +08:00
parent 2478f1a91e
commit 6d093c327f
2 changed files with 27 additions and 1 deletions

View File

@ -1,3 +1,7 @@
import { db } from "@/db";
import { notFound } from "next/navigation";
import SnippetEditForm from "@/components/snippet-edit-form";
interface SnippetEditPageProps { interface SnippetEditPageProps {
params: Promise<{ params: Promise<{
id: string; id: string;
@ -7,5 +11,16 @@ interface SnippetEditPageProps {
export default async function SnippetEditPage(props: SnippetEditPageProps) { export default async function SnippetEditPage(props: SnippetEditPageProps) {
const params = await props.params; const params = await props.params;
const id = parseInt(params.id); const id = parseInt(params.id);
return <div>Editing snippet with id {id}</div>; const snippet = await db.snippet.findFirst({
where: { id },
});
if (!snippet) {
return notFound();
}
return (
<div>
<SnippetEditForm snippet={snippet} />
</div>
);
} }

View File

@ -0,0 +1,11 @@
"use client";
import { Snippet } from "@prisma/client";
interface SnippetEditFormProps {
snippet: Snippet;
}
export default function SnippetEditForm({ snippet }: SnippetEditFormProps) {
return <div>Client component has snippet with title {snippet.title}</div>;
}