mirror of
https://github.com/massbug/judge4c.git
synced 2025-07-03 15:20:50 +00:00
- 在编辑面板组件中添加 onUpdate属性,用于处理数据更新 - 新增 updateProblem 函数,实现问题数据的更新逻辑 - 在问题编辑页面中集成更新功能,实现即时保存
121 lines
3.2 KiB
TypeScript
121 lines
3.2 KiB
TypeScript
"use client";
|
|
|
|
import { ProblemFlexLayout } from '@/features/problems/components/problem-flexlayout';
|
|
import { EditDescriptionPanel } from '@/components/creater/edit-description-panel';
|
|
import { EditSolutionPanel } from '@/components/creater/edit-solution-panel';
|
|
import { EditTestcasePanel } from '@/components/creater/edit-testcase-panel';
|
|
import { EditDetailPanel } from '@/components/creater/edit-detail-panel';
|
|
import { EditCodePanel } from '@/components/creater/edit-code-panel';
|
|
import { updateProblem } from '@/app/actions/updateProblem';
|
|
|
|
interface ProblemEditorPageProps {
|
|
params: Promise<{ problemId: string }>;
|
|
}
|
|
|
|
interface UpdateData {
|
|
content: string;
|
|
language?: 'c' | 'cpp';
|
|
inputs?: Array<{ index: number; name: string; value: string }>;
|
|
}
|
|
|
|
const handleUpdate = async (
|
|
updateFn: (data: UpdateData) => Promise<{ success: boolean }>,
|
|
data: UpdateData
|
|
) => {
|
|
try {
|
|
const result = await updateFn(data);
|
|
if (!result.success) {
|
|
// 这里可以添加更具体的错误处理
|
|
}
|
|
return result;
|
|
} catch (error) {
|
|
console.error('更新失败:', error);
|
|
return { success: false };
|
|
}
|
|
};
|
|
|
|
export default async function ProblemEditorPage({
|
|
params,
|
|
}: ProblemEditorPageProps) {
|
|
const { problemId } = await params;
|
|
|
|
const components: Record<string, React.ReactNode> = {
|
|
description: <EditDescriptionPanel
|
|
problemId={problemId}
|
|
onUpdate={async (data) => {
|
|
await handleUpdate(
|
|
(descriptionData) => updateProblem({
|
|
problemId,
|
|
displayId: 0,
|
|
description: descriptionData.content
|
|
}),
|
|
data
|
|
);
|
|
}}
|
|
/>,
|
|
solution: <EditSolutionPanel
|
|
problemId={problemId}
|
|
onUpdate={async (data) => {
|
|
await handleUpdate(
|
|
(solutionData) => updateProblem({
|
|
problemId,
|
|
displayId: 0,
|
|
solution: solutionData.content
|
|
}),
|
|
data
|
|
);
|
|
}}
|
|
/>,
|
|
detail: <EditDetailPanel
|
|
problemId={problemId}
|
|
onUpdate={async (data) => {
|
|
await handleUpdate(
|
|
(detailData) => updateProblem({
|
|
problemId,
|
|
displayId: 0,
|
|
detail: detailData.content
|
|
}),
|
|
data
|
|
);
|
|
}}
|
|
/>,
|
|
code: <EditCodePanel
|
|
problemId={problemId}
|
|
onUpdate={async (data) => {
|
|
await handleUpdate(
|
|
(codeData) => updateProblem({
|
|
problemId,
|
|
displayId: 0,
|
|
templates: [{
|
|
language: codeData.language || 'c', // 添加默认值
|
|
content: codeData.content
|
|
}]
|
|
}),
|
|
data
|
|
);
|
|
}}
|
|
/>,
|
|
testcase: <EditTestcasePanel
|
|
problemId={problemId}
|
|
onUpdate={async (data) => {
|
|
await handleUpdate(
|
|
(testcaseData) => updateProblem({
|
|
problemId,
|
|
displayId: 0,
|
|
testcases: [{
|
|
expectedOutput: testcaseData.content,
|
|
inputs: testcaseData.inputs || [] // 添加默认空数组
|
|
}]
|
|
}),
|
|
data
|
|
);
|
|
}}
|
|
/>
|
|
};
|
|
|
|
return (
|
|
<div className="relative flex h-full w-full">
|
|
<ProblemFlexLayout components={components} />
|
|
</div>
|
|
);
|
|
} |