forked from hydro-dev/Hydro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblemConfigForm.tsx
More file actions
112 lines (108 loc) · 4.1 KB
/
Copy pathProblemConfigForm.tsx
File metadata and controls
112 lines (108 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { CustomSelectAutoComplete } from '@hydrooj/components';
import {
Card, InputGroup, Tag,
} from '@blueprintjs/core';
import { isEqual } from 'lodash';
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { i18n } from 'vj/utils';
import FileSelectAutoComplete from '../autocomplete/components/FileSelectAutoComplete';
import { FormItem } from './BasicForm';
import ProblemType from './ProblemType';
import type { RootState } from './reducer/index';
function FileIOConfig() {
const filename = useSelector((state: RootState) => state.config.filename);
const dispatch = useDispatch();
return (
<FormItem columns={12} label="FileIOConfig" disableLabel>
<Card style={{ padding: 10 }}>
<div className="row">
<FormItem columns={6} label="FileIO">
<InputGroup
rightElement={<Tag minimal>.in/.out</Tag>}
value={filename || ''}
onChange={(ev) => {
dispatch({ type: 'problemconfig/updateFileIO', filename: ev.currentTarget.value });
}}
fill
/>
</FormItem>
</div>
</Card>
</FormItem>
);
}
function ExtraFilesConfig() {
const Files = useSelector((state: RootState) => state.testdata);
const userExtraFiles = useSelector((state: RootState) => state.config.user_extra_files || [], isEqual);
const judgeExtraFiles = useSelector((state: RootState) => state.config.judge_extra_files || [], isEqual);
const dispatch = useDispatch();
return (
<FormItem columns={12} label="ExtraFilesConfig" disableLabel>
<Card style={{ padding: 10 }}>
<div className="row">
<FormItem columns={12} label={i18n('user_extra_files')}>
<FileSelectAutoComplete
data={Files}
selectedKeys={userExtraFiles}
onChange={(val) => dispatch({ type: 'CONFIG_FORM_UPDATE', key: 'user_extra_files', value: val.split(',') })}
multi
/>
</FormItem>
<FormItem columns={12} label={i18n('judge_extra_files')}>
<FileSelectAutoComplete
data={Files}
selectedKeys={judgeExtraFiles}
onChange={(val) => dispatch({ type: 'CONFIG_FORM_UPDATE', key: 'judge_extra_files', value: val.split(',') })}
multi
/>
</FormItem>
</div>
</Card>
</FormItem>
);
}
function LangConfig() {
const langs = useSelector((state: RootState) => state.config.langs) || [];
const prefixes = new Set(Object.keys(window.LANGS).filter((i) => i.includes('.')).map((i) => i.split('.')[0]));
const data = Object.keys(window.LANGS).filter((i) => !prefixes.has(i))
.map((i) => ({ name: `${i.includes('.') ? `${window.LANGS[i.split('.')[0]].display || ''}/` : ''}${window.LANGS[i].display}`, _id: i }));
const dispatch = useDispatch();
const selectedKeys = langs.filter((i) => !prefixes.has(i));
return (
<FormItem columns={12} label="langs" disableLabel>
<Card style={{ padding: 10 }}>
<div className="row">
<FormItem columns={12} label="langs">
<CustomSelectAutoComplete
data={data}
placeholder={!selectedKeys.length ? i18n('Unlimited') : i18n('Code language')}
selectedKeys={selectedKeys}
onChange={(val) => {
const value = val.split(',');
value.push(...Array.from(new Set(value.filter((i) => i.includes('.')).map((i) => i.split('.')[0]).filter((i) => prefixes.has(i)))));
dispatch({ type: 'CONFIG_FORM_UPDATE', key: 'langs', value });
}}
multi
/>
</FormItem>
</div>
</Card>
</FormItem>
);
}
export default function ProblemConfigForm() {
const Type = useSelector((state: RootState) => state.config.type);
return (
<div className="row problem-config-form">
<ProblemType />
{Type === 'default' && <FileIOConfig />}
{!['submit_answer', 'objective'].includes(Type) && (
<>
<ExtraFilesConfig />
<LangConfig />
</>
)}
</div>
);
}