"use client"; import { useState, useEffect } from "react"; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import MdxPreview from "@/components/mdx-preview"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { CoreEditor } from "@/components/core-editor"; import { getProblemData } from "@/app/actions/getProblem";// 修改为你实际路径 export default function EditSolutionPanel({ problemId, }: { problemId: string; }) { const [solution, setSolution] = useState({ title: `Solution for Problem ${problemId}`, content: `Solution content for Problem ${problemId}...`, }); const [viewMode, setViewMode] = useState<"edit" | "preview" | "compare">("edit"); useEffect(() => { async function fetchSolution() { try { const data = await getProblemData(problemId); setSolution({ title: data.title ? data.title + " 解析" : `Solution for Problem ${problemId}`, content: data.solution || "", }); } catch (error) { console.error("加载题解失败", error); } } fetchSolution(); }, [problemId]); return ( 题目解析
setSolution({ ...solution, title: e.target.value })} placeholder="输入题解标题" />
setSolution({ ...solution, content: newContent })} language="markdown" className="absolute inset-0 rounded-md border border-input" />
{viewMode !== "edit" && (
)}
); }