ui: add problem submit limit (#366)

This commit is contained in:
panda authored and GitHub committed 2022-05-28 22:16:54 +08:00
1 parent 56396940fc
commit add66f26cf
3 files changed
+39 -3

No files matched your search

@@ -19,6 +19,7 @@ const mapStateToProps = (state) => ({
recordsVisible: state.ui.records.visible, recordsVisible: state.ui.records.visible,
isPosting: state.ui.isPosting, isPosting: state.ui.isPosting,
isRunning: state.pretest.isRunning, isRunning: state.pretest.isRunning,
isWaiting: state.ui.isWaiting,
editorLang: state.editor.lang, editorLang: state.editor.lang,
editorCode: state.editor.code, editorCode: state.editor.code,
pretestInput: state.pretest.input, pretestInput: state.pretest.input,
@@ -65,6 +66,12 @@ const mapDispatchToProps = (dispatch) => ({
payload: request.get(UiContext.getSubmissionsUrl), payload: request.get(UiContext.getSubmissionsUrl),
}); });
}, },
endWaiting() {
dispatch({
type: 'SCRATCHPAD_WAITING_END',
payload: 0,
});
},
}); });
const availableLangs = getAvailableLangs(UiContext.pdoc.config.langs); const availableLangs = getAvailableLangs(UiContext.pdoc.config.langs);
@@ -77,6 +84,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { waitSec: -1 };
if (!availableLangs[this.props.editorLang]) { if (!availableLangs[this.props.editorLang]) {
// preference not allowed // preference not allowed
const key = keys.find((i) => availableLangs[i].pretest === this.props.editorLang); const key = keys.find((i) => availableLangs[i].pretest === this.props.editorLang);
@@ -88,6 +96,21 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
if (this.props.recordsVisible) this.props.loadSubmissions(); if (this.props.recordsVisible) this.props.loadSubmissions();
} }
componentDidUpdate() {
if (this.props.isWaiting) {
const { waitSec } = this.state;
if (waitSec < 0) this.setState({ waitSec: 5 });
if (waitSec === 0) {
this.setState({ waitSec: waitSec - 1 });
this.props.endWaiting();
} else {
setTimeout(() => {
this.setState({ waitSec: waitSec - 1 });
}, 1000);
}
}
}
render() { render() {
let canUsePretest = ['default', 'fileio'].includes(UiContext.pdoc.config?.type); let canUsePretest = ['default', 'fileio'].includes(UiContext.pdoc.config?.type);
if (UiContext.pdoc.config?.type === 'remote_judge') { if (UiContext.pdoc.config?.type === 'remote_judge') {
@@ -98,7 +121,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
<Toolbar> <Toolbar>
{canUsePretest && ( {canUsePretest && (
<ToolbarButton <ToolbarButton
disabled={this.props.isPosting || this.props.isRunning} disabled={this.props.isPosting || this.props.isRunning || this.props.isWaiting}
className="scratchpad__toolbar__pretest" className="scratchpad__toolbar__pretest"
onClick={() => this.props.postPretest(this.props)} onClick={() => this.props.postPretest(this.props)}
data-global-hotkey="f9" data-global-hotkey="f9"
@@ -109,10 +132,12 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
{i18n('Run Pretest')} {i18n('Run Pretest')}
{' '} {' '}
(F9) (F9)
{' '}
{this.props.isWaiting && `(${this.state.waitSec}s)`}
</ToolbarButton> </ToolbarButton>
)} )}
<ToolbarButton <ToolbarButton
disabled={this.props.isPosting} disabled={this.props.isPosting || this.props.isWaiting}
className="scratchpad__toolbar__submit" className="scratchpad__toolbar__submit"
onClick={() => this.props.postSubmit(this.props)} onClick={() => this.props.postSubmit(this.props)}
data-global-hotkey="f10" data-global-hotkey="f10"
@@ -123,6 +148,8 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
{i18n('Submit Solution')} {i18n('Submit Solution')}
{' '} {' '}
(F10) (F10)
{' '}
{this.props.isWaiting && `(${this.state.waitSec}s)`}
</ToolbarButton> </ToolbarButton>
<ToolbarButton <ToolbarButton
data-global-hotkey="alt+q" data-global-hotkey="alt+q"
@@ -17,6 +17,7 @@ export default function reducer(state = {
isLoading: false, isLoading: false,
}, },
isPosting: false, isPosting: false,
isWaiting: false,
}, action) { }, action) {
switch (action.type) { switch (action.type) {
case 'SCRATCHPAD_UI_CHANGE_SIZE': { case 'SCRATCHPAD_UI_CHANGE_SIZE': {
@@ -67,6 +68,7 @@ export default function reducer(state = {
return { return {
...state, ...state,
isPosting: false, isPosting: false,
isWaiting: true,
}; };
} }
case 'SCRATCHPAD_POST_PRETEST_REJECTED': case 'SCRATCHPAD_POST_PRETEST_REJECTED':
@@ -75,6 +77,7 @@ export default function reducer(state = {
return { return {
...state, ...state,
isPosting: false, isPosting: false,
isWaiting: true,
}; };
} }
case 'SCRATCHPAD_RECORDS_LOAD_SUBMISSIONS_PENDING': { case 'SCRATCHPAD_RECORDS_LOAD_SUBMISSIONS_PENDING': {
@@ -105,6 +108,12 @@ export default function reducer(state = {
}, },
}; };
} }
case 'SCRATCHPAD_WAITING_END': {
return {
...state,
isWaiting: false,
};
}
default: default:
return state; return state;
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/ui-default", "name": "@hydrooj/ui-default",
"version": "4.37.11", "version": "4.37.12",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "hydro.js", "main": "hydro.js",