2025-06-16 10:37:25 +00:00
|
|
|
"use client";
|
|
|
|
|
2025-06-16 10:37:25 +00:00
|
|
|
import { useState } from "react";
|
2025-06-16 10:37:25 +00:00
|
|
|
import { Label } from "@/components/ui/label";
|
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
import { Button } from "@/components/ui/button";
|
2025-06-17 08:18:59 +00:00
|
|
|
import MdxPreview from "@/components/mdx-preview";
|
2025-06-16 14:41:48 +00:00
|
|
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|
|
|
import {CoreEditor} from "@/components/core-editor";
|
2025-06-16 10:37:25 +00:00
|
|
|
|
2025-06-16 10:37:25 +00:00
|
|
|
interface EditSolutionPanelProps {
|
|
|
|
problemId: string;
|
|
|
|
}
|
2025-06-20 03:42:10 +00:00
|
|
|
|
2025-06-16 10:37:25 +00:00
|
|
|
export const EditSolutionPanel = ({
|
|
|
|
problemId,
|
|
|
|
}: EditSolutionPanelProps) => {
|
|
|
|
const [title, setTitle] = useState(`Solution for Problem ${problemId}`);
|
|
|
|
const [content, setContent] = useState(`Solution content for Problem ${problemId}...`);
|
|
|
|
const [viewMode, setViewMode] = useState<'edit' | 'preview' | 'compare'>('edit');
|
2025-06-16 10:37:25 +00:00
|
|
|
|
|
|
|
return (
|
2025-06-16 14:41:48 +00:00
|
|
|
<Card className="w-full">
|
|
|
|
<CardHeader>
|
|
|
|
<CardTitle>题目解析</CardTitle>
|
|
|
|
</CardHeader>
|
|
|
|
<CardContent>
|
|
|
|
<div className="space-y-6">
|
|
|
|
<div className="space-y-2">
|
|
|
|
<Label htmlFor="solution-title">题解标题</Label>
|
|
|
|
<Input
|
|
|
|
id="solution-title"
|
|
|
|
value={title}
|
|
|
|
onChange={(e) => setTitle(e.target.value)}
|
|
|
|
placeholder="输入题解标题"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="flex space-x-2">
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
variant={viewMode === 'edit' ? 'default' : 'outline'}
|
|
|
|
onClick={() => setViewMode('edit')}
|
|
|
|
>
|
|
|
|
编辑
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
variant={viewMode === 'preview' ? 'default' : 'outline'}
|
|
|
|
onClick={() => setViewMode(viewMode === 'preview' ? 'edit' : 'preview')}
|
|
|
|
>
|
|
|
|
{viewMode === 'preview' ? '取消' : '预览'}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
variant={viewMode === 'compare' ? 'default' : 'outline'}
|
|
|
|
onClick={() => setViewMode('compare')}
|
|
|
|
>
|
|
|
|
对比
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className={viewMode === 'compare' ? "grid grid-cols-2 gap-6" : "flex flex-col gap-6"}>
|
|
|
|
<div className={viewMode === 'edit' || viewMode === 'compare' ? "block" : "hidden"}>
|
|
|
|
<div className="relative h-[600px]">
|
|
|
|
<CoreEditor
|
|
|
|
value={content}
|
|
|
|
onChange={setContent}
|
|
|
|
language="markdown"
|
|
|
|
className="absolute inset-0 rounded-md border border-input"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className={viewMode === 'preview' || viewMode === 'compare' ? "block" : "hidden"}>
|
|
|
|
<MdxPreview source={content} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Button>保存题解</Button>
|
2025-06-16 10:37:25 +00:00
|
|
|
</div>
|
2025-06-16 14:41:48 +00:00
|
|
|
</CardContent>
|
|
|
|
</Card>
|
2025-06-16 10:37:25 +00:00
|
|
|
);
|
2025-06-16 10:37:25 +00:00
|
|
|
};
|