import { Card, SegmentedControl, Switch } from '@mantine/core'; import React, { useEffect } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { i18n } from 'vj/utils'; import { testlibCheckers } from '../monaco/schema/problemconfig'; import { FormItem, ManagedSelect, SingleFileSelect } from './BasicForm'; import type { RootState } from './reducer/index'; export default function ProblemType() { const Type = useSelector((state: RootState) => state.config.type); const checkerType = useSelector((state: RootState) => state.config.checker_type); const filename = useSelector((state: RootState) => state.config.filename); const numProcesses = useSelector((state: RootState) => state.config.num_processes); const subType = useSelector((state: RootState) => state.config.subType); const checker = useSelector((state: RootState) => state.config.checker); const [category, setCategory] = React.useState(''); const dispatch = useDispatch(); const dispatcher = (base) => (value) => dispatch({ ...base, value }); useEffect(() => { if (category || !checker) return; const name = typeof checker === 'string' ? checker : checker.file; if (name.includes('.')) setCategory('custom'); else setCategory('preset'); }, [checker]); return (
{i18n('Problem Type')}
{['default', 'submit_answer'].includes(Type) && ( <>
{i18n('CheckerType')}
{ dispatch({ type: 'CONFIG_FORM_UPDATE', key: 'checker_type', value }); if (value === 'testlib' && !category) setCategory('custom'); }} data={[ { label: i18n('default'), value: 'default' }, { label: 'testlib', value: 'testlib' }, { label: 'other', value: 'other' }, ]} />
{((['strict', 'default'].includes(checkerType) || !checkerType)) && ( { dispatch({ type: 'CONFIG_FORM_UPDATE', key: 'checker_type', value: checkerType === 'strict' ? 'default' : 'strict' }); }} /> )} {(!['strict', 'default'].includes(checkerType) && checkerType && checkerType === 'testlib') && (
{category === 'preset' ? : }
)} {(!['strict', 'default'].includes(checkerType) && checkerType && checkerType !== 'testlib') && (
)} )} {Type === 'interactive' && (
)} {Type === 'communication' && (
dispatch(({ type: 'CONFIG_FORM_UPDATE', key: 'num_processes', value: +ev.currentTarget.value }))} className="textbox" />
)} {Type === 'submit_answer' && (
{ dispatch({ type: 'CONFIG_FORM_UPDATE', key: 'subType', value: subType === 'multi' ? 'single' : 'multi' }); }} /> dispatch(({ type: 'CONFIG_FORM_UPDATE', key: 'filename', value: ev.currentTarget.value }))} className="textbox" />
)} {Type === 'objective' && (

{i18n('Unsupported configure this type of problem. Please refer to the documentation.')}

)}
); }