From 6c6147d0506f0f8cac96440d5e83d882365c433f Mon Sep 17 00:00:00 2001 From: undefined Date: Thu, 16 Mar 2023 18:24:20 +0800 Subject: [PATCH] ui: problemconfig: bug fix --- .../ui-default/components/problemconfig/reducer/config.ts | 2 +- .../components/problemconfig/tree/SubtaskSettings.tsx | 2 +- packages/ui-default/pages/problem_config.page.tsx | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/ui-default/components/problemconfig/reducer/config.ts b/packages/ui-default/components/problemconfig/reducer/config.ts index 527e6f6b..9849568e 100644 --- a/packages/ui-default/components/problemconfig/reducer/config.ts +++ b/packages/ui-default/components/problemconfig/reducer/config.ts @@ -25,7 +25,7 @@ export default function reducer(state = { return { ...state, __valid: false, __errors: validate.errors.map((i) => `${i.instancePath}: ${i.message}`) }; } const subtasks = (data as any).subtasks; - for (const subtask of subtasks) { + for (const subtask of subtasks || []) { if (typeof subtask.id !== 'number') { for (let i = 1; ; i++) { if (!subtasks.find((s) => s.id === i)) { diff --git a/packages/ui-default/components/problemconfig/tree/SubtaskSettings.tsx b/packages/ui-default/components/problemconfig/tree/SubtaskSettings.tsx index 9a58016f..0abc4a47 100644 --- a/packages/ui-default/components/problemconfig/tree/SubtaskSettings.tsx +++ b/packages/ui-default/components/problemconfig/tree/SubtaskSettings.tsx @@ -126,7 +126,7 @@ export function SubtaskSettings(props: SubtaskSettingsProps) { {i18n('Scoring method')} - setType(e.target.value)}> diff --git a/packages/ui-default/pages/problem_config.page.tsx b/packages/ui-default/pages/problem_config.page.tsx index 8254f206..dac783de 100644 --- a/packages/ui-default/pages/problem_config.page.tsx +++ b/packages/ui-default/pages/problem_config.page.tsx @@ -104,7 +104,12 @@ const page = new NamedPage('problem_config', () => { if (!state.config.__loaded) return; if (state.config.cases) { const score = state.config.score * state.config.cases.length; - state.config.subtasks = [{ type: 'sum' as SubtaskType, score: score && score < 100 ? score : 100, cases: state.config.cases }]; + state.config.subtasks = [{ + type: 'sum' as SubtaskType, + score: score && score < 100 ? score : 100, + cases: state.config.cases, + id: 1, + }]; delete state.config.cases; delete state.config.score; }