ui: judge_config: add fast input case (#413)

Co-authored-by: undefined <i@undefined.moe>
This commit is contained in:
pandaandundefined authored and GitHub committed 2022-08-21 15:12:04 +08:00
1 parent b3e975cf38
commit b7cdadc255
6 files changed
+48 -8

No files matched your search

@@ -233,6 +233,7 @@ const AutoComplete = forwardRef(function Impl<T>(props: AutoCompleteProps<T>, re
setSelectedItems: (items) => {
setSelected(items);
setSelectedKeys(items.map((i) => itemKey(i)));
if (!multi && inputRef.current) inputRef.current.value = items.map((i) => itemKey(i)).join(',');
},
getQuery: () => inputRef.current?.value,
setQuery: (query) => {
@@ -2,7 +2,7 @@ import { NumericInput, Tag } from '@blueprintjs/core';
import { parseMemoryMB, parseTimeMS } from '@hydrooj/utils/lib/common';
import type { SubtaskConfig } from 'hydrooj/src/interface';
import { isEqual } from 'lodash';
import React from 'react';
import React, { useEffect, useRef } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import i18n from 'vj/utils/i18n';
import FileSelectAutoComplete from '../autocomplete/components/FileSelectAutoComplete';
@@ -29,7 +29,40 @@ export function TestCaseEntry({ index, subindex }) {
casesKey,
value,
});
if ((casesKey === 'input' && (value as string).endsWith('.in') && !testcase.output)
|| (casesKey === 'output' && (value as string).endsWith('.out') && !testcase.input)) {
const filename = (value as string).substring(0, (value as string).lastIndexOf('.'));
if (!testcase.output && (Files.map((f) => f.name).includes(`${filename}.out`) || Files.map((f) => f.name).includes(`${filename}.ans`))) {
dispatch({
type: 'CONFIG_SUBTASK_UPDATE',
id: index,
key: 'cases-edit',
casesId: subindex,
casesKey: 'output',
value: Files.map((f) => f.name).includes(`${filename}.out`) ? `${filename}.out` : `${filename}.ans`,
});
}
if (!testcase.input && Files.map((f) => f.name).includes(`${filename}.in`)) {
dispatch({
type: 'CONFIG_SUBTASK_UPDATE',
id: index,
key: 'cases-edit',
casesId: subindex,
casesKey: 'input',
value: `${filename}.in`,
});
}
}
};
const refs = {
input: useRef(),
output: useRef(),
};
for (const type of ['input', 'output']) {
useEffect(() => {
refs[type].current?.setSelectedItems(testcase[type] ? [testcase[type]] : []);
}, [testcase[type]]);
}
if (!testcase || Object.keys(testcase).length === 0) {
return (
<tr><td colSpan={5}>{i18n('Failed to parse testcase.')}</td></tr>
@@ -60,6 +93,7 @@ export function TestCaseEntry({ index, subindex }) {
{['input', 'output'].map((t) => (
<td key={t}>
<FileSelectAutoComplete
ref={refs[t]}
width="100%"
data={Files}
selectedKeys={[testcase[t]]}
@@ -48,7 +48,7 @@ export default function reducer(state = { type: 'default', __loaded: false } as
if (action.key.split('-')[0] === 'cases') {
if (action.key === 'cases-add') subsubtasks.cases.push(action.value);
else if (action.key === 'cases-edit') {
if (action.value === '') delete subsubtasks.cases[action.casesId][action.casesKey];
if (action.value === '' && !['input', 'output'].includes(action.casesKey)) delete subsubtasks.cases[action.casesId][action.casesKey];
else subsubtasks.cases[action.casesId][action.casesKey] = action.value;
} else if (action.key === 'cases-delete') {
subsubtasks.cases = subsubtasks.cases.filter((k, v) => v !== action.value);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/vjudge",
"version": "1.5.0-next.6",
"version": "1.5.0-next.7",
"description": "Submit problems to remote oj",
"main": "package.json",
"repository": "https://github.com/hydro-dev/Hydro.git",
+1 -1
View File
@@ -32,7 +32,7 @@ export interface IBasicProvider {
}>;
entryProblemLists?: string[];
listProblem(page: number, resync: boolean, listId: string): Promise<string[]>;
submitProblem(id: string, lang: string, code: string, info: any, next: any, end: any): Promise<string>;
submitProblem(id: string, lang: string, code: string, info: any, next: any, end: any): Promise<string | void>;
waitForSubmission(id: string, next: any, end: any): Promise<void>;
}
+9 -4
View File
@@ -89,8 +89,6 @@ export default class LuoguProvider implements IBasicProvider {
}
async getProblem(id: string) {
logger.info(id);
// TODO
return {
title: id,
data: {},
@@ -104,9 +102,16 @@ export default class LuoguProvider implements IBasicProvider {
return [];
}
async submitProblem(id: string, lang: string, code: string, info) {
async submitProblem(id: string, lang: string, code: string, info, next, end) {
let enableO2 = 0;
const comment = setting.langs[lang]?.comment;
if (code.length < 10) {
end({ status: STATUS.STATUS_COMPILE_ERROR, message: 'Code too short' });
return null;
}
if (!lang.startsWith('luogu.')) {
end({ status: STATUS.STATUS_COMPILE_ERROR, message: `Language not supported: ${lang}` });
}
if (comment) {
const msg = `Hydro submission #${info.rid}@${new Date().toLocaleString()}`;
if (typeof comment === 'string') code = `${comment} ${msg}\n${code}`;
@@ -116,7 +121,7 @@ export default class LuoguProvider implements IBasicProvider {
enableO2 = 1;
lang = lang.slice(0, -2);
}
lang = lang.includes('luogu.') ? lang.split('luogu.')[1] : '0';
lang = lang.split('luogu.')[1];
const result = await this.post(`/fe/api/problem/submit/${id}${this.account.query || ''}`)
.set('referer', `https://www.luogu.com.cn/problem/${id}`)
.send({