import { Card, NumericInput, Tag } from '@blueprintjs/core'; import { pick, isEqual } from 'lodash'; import React from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { SubtaskConfig } from 'hydrooj/src/interface'; import { parseTimeMS, parseMemoryMB } from '@hydrooj/utils/lib/common'; import CustomSelectAutoComplete from '../autocomplete/components/CustomSelectAutoComplete'; import { FormItem, ManagedInput } from './BasicForm'; import { RootState } from './reducer'; import { CasesTable } from './TestCasesTable'; const eq = (a: SubtaskConfig, b: SubtaskConfig) => isEqual(a, b); export function SubtasksIds({ index }) { const ids = useSelector((state: RootState) => state.config.subtasks.map((i) => i.id).filter((i) => i !== undefined).join(',')); const subtaskIf = useSelector((state: RootState) => state.config.subtasks[index].if); const dispatch = useDispatch(); return ( if i.length)} selectedKeys={subtaskIf?.map(String) || []} onChange={(val) => dispatch({ type: 'CONFIG_SUBTASK_UPDATE', id: index, key: 'if', value: val.split(','), })} multi /> ); } export function SubtasksTable({ index }) { const keys = ['id', 'type', 'score', 'time', 'memory']; const subtask = useSelector((state: RootState) => pick(state.config.subtasks[index], keys), eq); const defaultTime = useSelector((state: RootState) => state.config.time); const defaultMemory = useSelector((state: RootState) => state.config.memory); const dispatch = useDispatch(); const dispatcher = (key: string, suffix = '') => (ev: React.ChangeEvent | number) => { let value = typeof ev !== 'object' ? ev : ev.currentTarget?.value; if (value === 0) value = ''; if (value && suffix) value += suffix; dispatch({ type: 'CONFIG_SUBTASK_UPDATE', id: index, key, value, }); }; return ( Subtasks #{index + 1} dispatch({ type: 'CONFIG_SUBTASK_UPDATE', id: index, key: 'add' })}> dispatch({ type: 'CONFIG_SUBTASK_UPDATE', id: index, key: 'delete' })} > {['id', 'score'].map((key) => ( ))}
# Score Type Time Memory
ms} value={subtask.time ? parseTimeMS(subtask.time).toString() : ''} placeholder={parseTimeMS(defaultTime || '1000ms').toString()} onValueChange={dispatcher('time', 'ms')} buttonPosition="none" fill /> MB} value={subtask.memory ? parseMemoryMB(subtask.memory).toString() : ''} placeholder={parseMemoryMB(defaultMemory || '256m').toString()} onValueChange={dispatcher('memory', 'MB')} buttonPosition="none" fill />
); } export function TaskConfig() { const len = useSelector((state: RootState) => state.config.subtasks?.length); return (
{len && [...Array(len).keys()].map((i) => )}
); }