mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
添加功能:pretest discuss user dashboard statistics
This commit is contained in:
1 parent
61cba6f180
commit
15d43636c0
41 files changed
+920
-523
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import _ from 'lodash';
|
||||
|
||||
const initialId = uuid();
|
||||
|
||||
@@ -23,67 +22,6 @@ export default function reducer(state = {
|
||||
},
|
||||
}, action) {
|
||||
switch (action.type) {
|
||||
case 'SCRATCHPAD_PRETEST_SWITCH_TO_DATA': {
|
||||
const currentId = action.payload;
|
||||
return {
|
||||
...state,
|
||||
current: currentId,
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_PRETEST_ADD_DATA': {
|
||||
const newCounter = state.counter + 1;
|
||||
const newId = uuid();
|
||||
return {
|
||||
...state,
|
||||
counter: newCounter,
|
||||
current: newId,
|
||||
tabs: [...state.tabs, newId],
|
||||
meta: {
|
||||
...state.meta,
|
||||
[newId]: {
|
||||
id: newId,
|
||||
title: `#${newCounter}`,
|
||||
},
|
||||
},
|
||||
data: {
|
||||
...state.data,
|
||||
[newId]: {
|
||||
id: newId,
|
||||
input: '',
|
||||
output: '',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_PRETEST_REMOVE_DATA': {
|
||||
const orgIdx = state.tabs.indexOf(state.current);
|
||||
let newCounter = state.counter;
|
||||
const newTabs = _.without(state.tabs, state.current);
|
||||
const newMeta = _.omit(state.meta, state.current);
|
||||
const newData = _.omit(state.data, state.current);
|
||||
if (newTabs.length === 0) {
|
||||
// keep at least one data
|
||||
const id = uuid();
|
||||
newTabs.push(id);
|
||||
newMeta[id] = {
|
||||
id,
|
||||
title: `#${++newCounter}`,
|
||||
};
|
||||
newData[id] = {
|
||||
input: '',
|
||||
output: '',
|
||||
};
|
||||
}
|
||||
const newIdx = (orgIdx < newTabs.length) ? orgIdx : orgIdx - 1;
|
||||
return {
|
||||
...state,
|
||||
counter: newCounter,
|
||||
current: newTabs[newIdx],
|
||||
tabs: newTabs,
|
||||
meta: newMeta,
|
||||
data: newData,
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_PRETEST_DATA_CHANGE': {
|
||||
const { id, type, value } = action.payload;
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user