From e435ddaddd1b07379a59e287123e90c1d74edde6 Mon Sep 17 00:00:00 2001 From: panda Date: Wed, 20 Mar 2024 22:08:20 +0800 Subject: [PATCH] ui: fix problem_config testlib select (#762) --- .../components/problemconfig/ProblemType.tsx | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/ui-default/components/problemconfig/ProblemType.tsx b/packages/ui-default/components/problemconfig/ProblemType.tsx index 260520085..4e9e18126 100644 --- a/packages/ui-default/components/problemconfig/ProblemType.tsx +++ b/packages/ui-default/components/problemconfig/ProblemType.tsx @@ -1,7 +1,7 @@ import { - Card, Classes, Switch, Tab, Tabs, + Card, Classes, Switch, Tab, Tabs, TabsExpander, } from '@blueprintjs/core'; -import React from 'react'; +import React, { useEffect } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { i18n } from 'vj/utils'; import { testlibCheckers } from '../monaco/schema/problemconfig'; @@ -14,9 +14,14 @@ export default function ProblemType() { const filename = useSelector((state: RootState) => state.config.filename); const subType = useSelector((state: RootState) => state.config.subType); const checker = useSelector((state: RootState) => state.config.checker); - const [category, setCategory] = React.useState(checker?.includes('.') ? 'preset' : 'custom'); + const [category, setCategory] = React.useState(''); const dispatch = useDispatch(); const dispatcher = (base) => (value) => dispatch({ ...base, value }); + useEffect(() => { + if (category || !checker) return; + if (checker.includes('.')) setCategory('custom'); + else setCategory('preset'); + }, [checker]); return ( @@ -39,11 +44,14 @@ export default function ProblemType() { ['strict', 'default'].includes(checkerType) || !checkerType ? 'default' : (checkerType !== 'testlib' ? 'other' : 'testlib') } - onChange={dispatcher({ type: 'CONFIG_FORM_UPDATE', key: 'checker_type' })} + onChange={(value) => { + dispatch({ type: 'CONFIG_FORM_UPDATE', key: 'checker_type', value }); + if (value === 'testlib' && !category) setCategory('custom'); + }} renderActiveTabPanelOnly > {i18n('CheckerType')} - + { setCategory(ev.currentTarget.value); - dispatch({ type: 'CONFIG_FORM_UPDATE', key: 'checker', value: null }); + dispatch({ type: 'CONFIG_FORM_UPDATE', key: 'checker', value: ev.currentTarget.value === 'preset' ? 'acmp' : null }); }} className="select" >