feat: 添加SnippetShowForm组件,替换代码显示为可编辑的Monaco编辑器

This commit is contained in:
ngc2207 2024-11-12 19:23:13 +08:00
parent b529255006
commit 5a5a8033da
2 changed files with 30 additions and 4 deletions

View File

@ -2,6 +2,7 @@ import { db } from "@/db";
import Link from "next/link";
import * as actions from "@/actions";
import { notFound } from "next/navigation";
import SnippetShowForm from "@/components/snippet-show-form";
interface SnippetShowPageProps {
params: Promise<{
@ -29,7 +30,10 @@ export default async function SnippetShowPage(props: SnippetShowPageProps) {
<div>
<div className="flex m-4 justify-between items-center">
<h1 className="text-xl font-bold">{snippet.title}</h1>
<div className="flex gap-4">
<div className="flex gap-2">
<Link href="/" className="p-2 border rounded">
Home
</Link>
<Link
href={`/snippets/${snippet.id}/edit`}
className="p-2 border rounded"
@ -41,9 +45,9 @@ export default async function SnippetShowPage(props: SnippetShowPageProps) {
</form>
</div>
</div>
<pre className="p-3 border rounded bg-gray-200 border-gray-200">
<code>{snippet.code}</code>
</pre>
<div>
<SnippetShowForm snippet={snippet} />
</div>
</div>
);
}

View File

@ -0,0 +1,22 @@
"use client";
import { Snippet } from "@prisma/client";
import { Editor } from "@monaco-editor/react";
interface SnippetShowFormProps {
snippet: Snippet;
}
export default function SnippetShowForm({ snippet }: SnippetShowFormProps) {
return (
<div>
<Editor
height="40vh"
theme="vs-light"
language="c"
defaultValue={snippet.code}
options={{ minimap: { enabled: false } }}
/>
</div>
);
}