mirror of
https://litchi.icu/ngc2207/judge4c-demo.git
synced 2025-05-18 16:26:48 +00:00
feat: 添加删除代码片段功能,支持在代码片段页面删除指定代码片段
This commit is contained in:
parent
859fd0f725
commit
3474cb11af
@ -11,3 +11,9 @@ export async function editSnippet(id: number, code: string) {
|
|||||||
|
|
||||||
redirect(`/snippets/${id}`);
|
redirect(`/snippets/${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function deleteSnippet(id: number) {
|
||||||
|
await db.snippet.delete({ where: { id } });
|
||||||
|
|
||||||
|
redirect("/");
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { db } from "@/db";
|
import { db } from "@/db";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import * as actions from "@/actions";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
|
|
||||||
interface SnippetShowPageProps {
|
interface SnippetShowPageProps {
|
||||||
@ -22,6 +23,8 @@ export default async function SnippetShowPage(props: SnippetShowPageProps) {
|
|||||||
return notFound();
|
return notFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deleteSnippetAction = actions.deleteSnippet.bind(null, snippet.id);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="flex m-4 justify-between items-center">
|
<div className="flex m-4 justify-between items-center">
|
||||||
@ -33,7 +36,9 @@ export default async function SnippetShowPage(props: SnippetShowPageProps) {
|
|||||||
>
|
>
|
||||||
Edit
|
Edit
|
||||||
</Link>
|
</Link>
|
||||||
<button className="p-2 border rounded">Delete</button>
|
<form action={deleteSnippetAction}>
|
||||||
|
<button className="p-2 border rounded">Delete</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<pre className="p-3 border rounded bg-gray-200 border-gray-200">
|
<pre className="p-3 border rounded bg-gray-200 border-gray-200">
|
||||||
|
Loading…
Reference in New Issue
Block a user