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