mirror of
https://litchi.icu/ngc2207/judge4c-demo.git
synced 2025-05-18 16:37:12 +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}`);
|
||||
}
|
||||
|
||||
export async function deleteSnippet(id: number) {
|
||||
await db.snippet.delete({ where: { id } });
|
||||
|
||||
redirect("/");
|
||||
}
|
||||
|
@ -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 (
|
||||
<div>
|
||||
<div className="flex m-4 justify-between items-center">
|
||||
@ -33,7 +36,9 @@ export default async function SnippetShowPage(props: SnippetShowPageProps) {
|
||||
>
|
||||
Edit
|
||||
</Link>
|
||||
<form action={deleteSnippetAction}>
|
||||
<button className="p-2 border rounded">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<pre className="p-3 border rounded bg-gray-200 border-gray-200">
|
||||
|
Loading…
Reference in New Issue
Block a user