mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: simplify scratchpad countdown logic (#373)
This commit is contained in:
1 parent
8fc64a0654
commit
cb18ec19fe
3 files changed
+17
-29
No files matched your search
@@ -20,6 +20,7 @@ const mapStateToProps = (state) => ({
|
|||||||
isPosting: state.ui.isPosting,
|
isPosting: state.ui.isPosting,
|
||||||
isRunning: state.pretest.isRunning,
|
isRunning: state.pretest.isRunning,
|
||||||
isWaiting: state.ui.isWaiting,
|
isWaiting: state.ui.isWaiting,
|
||||||
|
waitSec: state.ui.waitSec,
|
||||||
editorLang: state.editor.lang,
|
editorLang: state.editor.lang,
|
||||||
editorCode: state.editor.code,
|
editorCode: state.editor.code,
|
||||||
pretestInput: state.pretest.input,
|
pretestInput: state.pretest.input,
|
||||||
@@ -66,10 +67,9 @@ const mapDispatchToProps = (dispatch) => ({
|
|||||||
payload: request.get(UiContext.getSubmissionsUrl),
|
payload: request.get(UiContext.getSubmissionsUrl),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
endWaiting() {
|
tick() {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'SCRATCHPAD_WAITING_END',
|
type: 'SCRATCHPAD_WAITING_TICK',
|
||||||
payload: 0,
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -84,7 +84,6 @@ 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);
|
||||||
@@ -97,18 +96,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
if (this.props.isWaiting) {
|
if (this.props.waitSec > 0) setTimeout(() => this.props.tick(), 1000);
|
||||||
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() {
|
||||||
@@ -131,9 +119,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
|
|||||||
{' '}
|
{' '}
|
||||||
{i18n('Run Pretest')}
|
{i18n('Run Pretest')}
|
||||||
{' '}
|
{' '}
|
||||||
(F9)
|
{this.props.isWaiting ? `(${this.props.waitSec}s)` : '(F9)'}
|
||||||
{' '}
|
|
||||||
{this.props.isWaiting && `(${this.state.waitSec}s)`}
|
|
||||||
</ToolbarButton>
|
</ToolbarButton>
|
||||||
)}
|
)}
|
||||||
<ToolbarButton
|
<ToolbarButton
|
||||||
@@ -147,9 +133,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
|
|||||||
{' '}
|
{' '}
|
||||||
{i18n('Submit Solution')}
|
{i18n('Submit Solution')}
|
||||||
{' '}
|
{' '}
|
||||||
(F10)
|
{this.props.isWaiting ? `(${this.props.waitSec}s)` : '(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,
|
||||||
|
waitSec: 0,
|
||||||
isWaiting: false,
|
isWaiting: false,
|
||||||
}, action) {
|
}, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
@@ -68,6 +69,7 @@ export default function reducer(state = {
|
|||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
isPosting: false,
|
isPosting: false,
|
||||||
|
waitSec: 5,
|
||||||
isWaiting: true,
|
isWaiting: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -77,9 +79,17 @@ export default function reducer(state = {
|
|||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
isPosting: false,
|
isPosting: false,
|
||||||
|
waitSec: 5,
|
||||||
isWaiting: true,
|
isWaiting: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
case 'SCRATCHPAD_WAITING_TICK': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
waitSec: state.waitSec - 1,
|
||||||
|
isWaiting: state.waitSec > 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
case 'SCRATCHPAD_RECORDS_LOAD_SUBMISSIONS_PENDING': {
|
case 'SCRATCHPAD_RECORDS_LOAD_SUBMISSIONS_PENDING': {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
@@ -108,12 +118,6 @@ export default function reducer(state = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case 'SCRATCHPAD_WAITING_END': {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
isWaiting: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.37.21",
|
"version": "4.37.22",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
|
|||||||
Reference in new issue
Block a user