"use client"; import { useState, useEffect } from "react"; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { getProblemData } from "@/app/actions/getProblem"; export default function EditDetailPanel({ problemId, }: { problemId: string; }) { const [problemDetails, setProblemDetails] = useState({ displayId: 1000, difficulty: "EASY" as "EASY" | "MEDIUM" | "HARD", timeLimit: 1000, memoryLimit: 134217728, isPublished: false, }); useEffect(() => { async function fetchData() { try { const problemData = await getProblemData(problemId); setProblemDetails({ displayId: problemData.displayId, difficulty: problemData.difficulty, timeLimit: problemData.timeLimit, memoryLimit: problemData.memoryLimit, isPublished: problemData.isPublished, }); } catch (error) { console.error("获取题目信息失败:", error); } } fetchData(); }, [problemId]); const handleNumberInputChange = ( e: React.ChangeEvent, field: keyof typeof problemDetails ) => { const value = parseInt(e.target.value, 10); if (!isNaN(value)) { setProblemDetails({ ...problemDetails, [field]: value, }); } }; const handleDifficultyChange = (e: React.ChangeEvent) => { const value = e.target.value; if (value === "EASY" || value === "MEDIUM" || value === "HARD") { setProblemDetails({ ...problemDetails, difficulty: value }); } }; return ( 题目详情
handleNumberInputChange(e, "displayId")} placeholder="输入显示ID" />
handleNumberInputChange(e, "timeLimit")} placeholder="输入时间限制" />
handleNumberInputChange(e, "memoryLimit")} placeholder="输入内存限制" />
setProblemDetails({ ...problemDetails, isPublished: e.target.checked }) } className="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600" />
); }