mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
ui: add problem submit limit (#366)
This commit is contained in:
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,
|
||||
isPosting: state.ui.isPosting,
|
||||
isRunning: state.pretest.isRunning,
|
||||
isWaiting: state.ui.isWaiting,
|
||||
editorLang: state.editor.lang,
|
||||
editorCode: state.editor.code,
|
||||
pretestInput: state.pretest.input,
|
||||
@@ -65,6 +66,12 @@ const mapDispatchToProps = (dispatch) => ({
|
||||
payload: request.get(UiContext.getSubmissionsUrl),
|
||||
});
|
||||
},
|
||||
endWaiting() {
|
||||
dispatch({
|
||||
type: 'SCRATCHPAD_WAITING_END',
|
||||
payload: 0,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const availableLangs = getAvailableLangs(UiContext.pdoc.config.langs);
|
||||
@@ -77,6 +84,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { waitSec: -1 };
|
||||
if (!availableLangs[this.props.editorLang]) {
|
||||
// preference not allowed
|
||||
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();
|
||||
}
|
||||
|
||||
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() {
|
||||
let canUsePretest = ['default', 'fileio'].includes(UiContext.pdoc.config?.type);
|
||||
if (UiContext.pdoc.config?.type === 'remote_judge') {
|
||||
@@ -98,7 +121,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
|
||||
<Toolbar>
|
||||
{canUsePretest && (
|
||||
<ToolbarButton
|
||||
disabled={this.props.isPosting || this.props.isRunning}
|
||||
disabled={this.props.isPosting || this.props.isRunning || this.props.isWaiting}
|
||||
className="scratchpad__toolbar__pretest"
|
||||
onClick={() => this.props.postPretest(this.props)}
|
||||
data-global-hotkey="f9"
|
||||
@@ -109,10 +132,12 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
|
||||
{i18n('Run Pretest')}
|
||||
{' '}
|
||||
(F9)
|
||||
{' '}
|
||||
{this.props.isWaiting && `(${this.state.waitSec}s)`}
|
||||
</ToolbarButton>
|
||||
)}
|
||||
<ToolbarButton
|
||||
disabled={this.props.isPosting}
|
||||
disabled={this.props.isPosting || this.props.isWaiting}
|
||||
className="scratchpad__toolbar__submit"
|
||||
onClick={() => this.props.postSubmit(this.props)}
|
||||
data-global-hotkey="f10"
|
||||
@@ -123,6 +148,8 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
|
||||
{i18n('Submit Solution')}
|
||||
{' '}
|
||||
(F10)
|
||||
{' '}
|
||||
{this.props.isWaiting && `(${this.state.waitSec}s)`}
|
||||
</ToolbarButton>
|
||||
<ToolbarButton
|
||||
data-global-hotkey="alt+q"
|
||||
|
||||
@@ -17,6 +17,7 @@ export default function reducer(state = {
|
||||
isLoading: false,
|
||||
},
|
||||
isPosting: false,
|
||||
isWaiting: false,
|
||||
}, action) {
|
||||
switch (action.type) {
|
||||
case 'SCRATCHPAD_UI_CHANGE_SIZE': {
|
||||
@@ -67,6 +68,7 @@ export default function reducer(state = {
|
||||
return {
|
||||
...state,
|
||||
isPosting: false,
|
||||
isWaiting: true,
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_POST_PRETEST_REJECTED':
|
||||
@@ -75,6 +77,7 @@ export default function reducer(state = {
|
||||
return {
|
||||
...state,
|
||||
isPosting: false,
|
||||
isWaiting: true,
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_RECORDS_LOAD_SUBMISSIONS_PENDING': {
|
||||
@@ -105,6 +108,12 @@ export default function reducer(state = {
|
||||
},
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_WAITING_END': {
|
||||
return {
|
||||
...state,
|
||||
isWaiting: false,
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/ui-default",
|
||||
"version": "4.37.11",
|
||||
"version": "4.37.12",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"license": "AGPL-3.0",
|
||||
"main": "hydro.js",
|
||||
|
||||
Reference in new issue
Block a user