From 3474cb11af02a1483967865756fed4dea58575c5 Mon Sep 17 00:00:00 2001 From: ngc2207 Date: Tue, 12 Nov 2024 16:42:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=89=87=E6=AE=B5=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=9C=A8=E4=BB=A3=E7=A0=81=E7=89=87=E6=AE=B5?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=88=A0=E9=99=A4=E6=8C=87=E5=AE=9A=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=89=87=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/actions/index.ts | 6 ++++++ src/app/snippets/[id]/page.tsx | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/actions/index.ts b/src/actions/index.ts index 88b5d62..5ceaf02 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -11,3 +11,9 @@ export async function editSnippet(id: number, code: string) { redirect(`/snippets/${id}`); } + +export async function deleteSnippet(id: number) { + await db.snippet.delete({ where: { id } }); + + redirect("/"); +} diff --git a/src/app/snippets/[id]/page.tsx b/src/app/snippets/[id]/page.tsx index 5b191f6..7f1495e 100644 --- a/src/app/snippets/[id]/page.tsx +++ b/src/app/snippets/[id]/page.tsx @@ -1,5 +1,6 @@ import { db } from "@/db"; import Link from "next/link"; +import * as actions from "@/actions"; import { notFound } from "next/navigation"; interface SnippetShowPageProps { @@ -22,6 +23,8 @@ export default async function SnippetShowPage(props: SnippetShowPageProps) { return notFound(); } + const deleteSnippetAction = actions.deleteSnippet.bind(null, snippet.id); + return (
@@ -33,7 +36,9 @@ export default async function SnippetShowPage(props: SnippetShowPageProps) { > Edit - +
+ +