mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: typed redux
This commit is contained in:
1 parent
e0f38fb0a8
commit
99b6ead86f
6 files changed
+4
-1
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { STATUS_TEXTS } from '@hydrooj/utils/lib/status';
|
||||
|
||||
export default function reducer(state = {
|
||||
input: '',
|
||||
output: '',
|
||||
rid: null,
|
||||
}, action) {
|
||||
if (action.type === 'SCRATCHPAD_PRETEST_DATA_CHANGE') {
|
||||
const { type, value } = action.payload;
|
||||
return {
|
||||
...state,
|
||||
[type]: value,
|
||||
};
|
||||
}
|
||||
if (action.type === 'SCRATCHPAD_RECORDS_PUSH') {
|
||||
const { rdoc } = action.payload;
|
||||
if (rdoc._id === state.rid) {
|
||||
const output = [`${STATUS_TEXTS[rdoc.status]} ${rdoc.time}ms ${rdoc.memory}KiB`];
|
||||
if (rdoc.compilerTexts.length) output.push(rdoc.compilerTexts.join('\n'));
|
||||
if (rdoc.testCases.length) output.push(rdoc.testCases[0].message || '');
|
||||
return {
|
||||
...state,
|
||||
output: output.join('\n'),
|
||||
};
|
||||
}
|
||||
}
|
||||
if (action.type === 'SCRATCHPAD_POST_PRETEST_FULFILLED') {
|
||||
return {
|
||||
...state,
|
||||
rid: action.payload.rid,
|
||||
};
|
||||
}
|
||||
return state;
|
||||
}
|
||||
Reference in new issue
Block a user