mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: scratchpad: use seperate cooldown for pretest and submit
This commit is contained in:
1 parent
4fa9df8c9b
commit
9dc6818fd7
3 files changed
+30
-20
No files matched your search
@@ -18,8 +18,8 @@ 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,
|
pretestWaitSec: state.ui.pretestWaitSec,
|
||||||
waitSec: state.ui.waitSec,
|
submitWaitSec: state.ui.submitWaitSec,
|
||||||
editorLang: state.editor.lang,
|
editorLang: state.editor.lang,
|
||||||
editorCode: state.editor.code,
|
editorCode: state.editor.code,
|
||||||
pretestInput: state.pretest.input,
|
pretestInput: state.pretest.input,
|
||||||
@@ -96,7 +96,9 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
if (this.props.waitSec > 0) setTimeout(() => this.props.tick(), 1000);
|
if (this.props.pretestWaitSec > 0 || this.props.submitWaitSec > 0) {
|
||||||
|
setTimeout(() => this.props.tick(), 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -109,7 +111,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
|
|||||||
<Toolbar>
|
<Toolbar>
|
||||||
{canUsePretest && (
|
{canUsePretest && (
|
||||||
<ToolbarButton
|
<ToolbarButton
|
||||||
disabled={this.props.isPosting || this.props.isRunning || this.props.isWaiting}
|
disabled={this.props.isPosting || this.props.isRunning || this.props.pretestWaitSec}
|
||||||
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"
|
||||||
@@ -119,11 +121,11 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
|
|||||||
{' '}
|
{' '}
|
||||||
{i18n('Run Pretest')}
|
{i18n('Run Pretest')}
|
||||||
{' '}
|
{' '}
|
||||||
{this.props.isWaiting ? `(${this.props.waitSec}s)` : '(F9)'}
|
{this.props.pretestWaitSec ? `(${this.props.pretestWaitSec}s)` : '(F9)'}
|
||||||
</ToolbarButton>
|
</ToolbarButton>
|
||||||
)}
|
)}
|
||||||
<ToolbarButton
|
<ToolbarButton
|
||||||
disabled={this.props.isPosting || this.props.isWaiting}
|
disabled={this.props.isPosting || this.props.submitWaitSec}
|
||||||
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"
|
||||||
@@ -133,7 +135,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
|
|||||||
{' '}
|
{' '}
|
||||||
{i18n('Submit Solution')}
|
{i18n('Submit Solution')}
|
||||||
{' '}
|
{' '}
|
||||||
{this.props.isWaiting ? `(${this.props.waitSec}s)` : '(F10)'}
|
{this.props.submitWaitSec ? `(${this.props.submitWaitSec}s)` : '(F10)'}
|
||||||
</ToolbarButton>
|
</ToolbarButton>
|
||||||
<ToolbarButton
|
<ToolbarButton
|
||||||
data-global-hotkey="alt+q"
|
data-global-hotkey="alt+q"
|
||||||
|
|||||||
@@ -18,8 +18,9 @@ export default function reducer(state = {
|
|||||||
isLoading: false,
|
isLoading: false,
|
||||||
},
|
},
|
||||||
isPosting: false,
|
isPosting: false,
|
||||||
waitSec: 0,
|
pretestWaitSec: 0,
|
||||||
isWaiting: false,
|
submitWaitSec: 0,
|
||||||
|
lastTick: 0,
|
||||||
activePage: 'problem',
|
activePage: 'problem',
|
||||||
}, action: any = {}) {
|
}, action: any = {}) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
@@ -65,14 +66,19 @@ export default function reducer(state = {
|
|||||||
case 'SCRATCHPAD_POST_PRETEST_FULFILLED':
|
case 'SCRATCHPAD_POST_PRETEST_FULFILLED':
|
||||||
case 'SCRATCHPAD_POST_SUBMIT_FULFILLED': {
|
case 'SCRATCHPAD_POST_SUBMIT_FULFILLED': {
|
||||||
Notification.success(i18n('Submitted.'));
|
Notification.success(i18n('Submitted.'));
|
||||||
if (action.type === 'SCRATCHPAD_POST_SUBMIT_FULFILLED' && UiContext.canViewRecord) {
|
return (action.type === 'SCRATCHPAD_POST_SUBMIT_FULFILLED' && UiContext.canViewRecord)
|
||||||
state.records.visible = true;
|
? {
|
||||||
}
|
...state,
|
||||||
return {
|
records: {
|
||||||
|
...state.records,
|
||||||
|
visible: true,
|
||||||
|
},
|
||||||
|
isPosting: false,
|
||||||
|
submitWaitSec: 8,
|
||||||
|
} : {
|
||||||
...state,
|
...state,
|
||||||
isPosting: false,
|
isPosting: false,
|
||||||
waitSec: 5,
|
pretestWaitSec: 5,
|
||||||
isWaiting: true,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case 'SCRATCHPAD_POST_PRETEST_REJECTED':
|
case 'SCRATCHPAD_POST_PRETEST_REJECTED':
|
||||||
@@ -81,15 +87,17 @@ export default function reducer(state = {
|
|||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
isPosting: false,
|
isPosting: false,
|
||||||
waitSec: 5,
|
pretestWaitSec: 3,
|
||||||
isWaiting: true,
|
submitWaitSec: 3,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case 'SCRATCHPAD_WAITING_TICK': {
|
case 'SCRATCHPAD_WAITING_TICK': {
|
||||||
|
if (Date.now() - state.lastTick < 950) return state;
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
waitSec: state.waitSec - 1,
|
lastTick: Date.now(),
|
||||||
isWaiting: state.waitSec > 1,
|
pretestWaitSec: Math.max(state.pretestWaitSec - 1, 0),
|
||||||
|
submitWaitSec: Math.max(state.submitWaitSec - 1, 0),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case 'SCRATCHPAD_RECORDS_LOAD_SUBMISSIONS_PENDING': {
|
case 'SCRATCHPAD_RECORDS_LOAD_SUBMISSIONS_PENDING': {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.42.13",
|
"version": "4.42.14",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
|
|||||||
Reference in new issue
Block a user