mirror of
https://litchi.icu/ngc2207/judge4c-demo.git
synced 2025-05-18 22:28:07 +00:00
feat: 添加SnippetShowForm组件,替换代码显示为可编辑的Monaco编辑器
This commit is contained in:
parent
b529255006
commit
5a5a8033da
@ -2,6 +2,7 @@ import { db } from "@/db";
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import * as actions from "@/actions";
|
import * as actions from "@/actions";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
|
import SnippetShowForm from "@/components/snippet-show-form";
|
||||||
|
|
||||||
interface SnippetShowPageProps {
|
interface SnippetShowPageProps {
|
||||||
params: Promise<{
|
params: Promise<{
|
||||||
@ -29,7 +30,10 @@ export default async function SnippetShowPage(props: SnippetShowPageProps) {
|
|||||||
<div>
|
<div>
|
||||||
<div className="flex m-4 justify-between items-center">
|
<div className="flex m-4 justify-between items-center">
|
||||||
<h1 className="text-xl font-bold">{snippet.title}</h1>
|
<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
|
<Link
|
||||||
href={`/snippets/${snippet.id}/edit`}
|
href={`/snippets/${snippet.id}/edit`}
|
||||||
className="p-2 border rounded"
|
className="p-2 border rounded"
|
||||||
@ -41,9 +45,9 @@ export default async function SnippetShowPage(props: SnippetShowPageProps) {
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<pre className="p-3 border rounded bg-gray-200 border-gray-200">
|
<div>
|
||||||
<code>{snippet.code}</code>
|
<SnippetShowForm snippet={snippet} />
|
||||||
</pre>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
22
src/components/snippet-show-form.tsx
Normal file
22
src/components/snippet-show-form.tsx
Normal 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>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user