mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
add ui
This commit is contained in:
1 parent
777a4bc927
commit
9c45527522
396 files changed
+13772
No files matched your search
@@ -0,0 +1,21 @@
|
||||
export default function reducer(state = {
|
||||
lang: Context.code_lang,
|
||||
code: Context.code_template,
|
||||
}, action) {
|
||||
switch (action.type) {
|
||||
case 'SCRATCHPAD_EDITOR_UPDATE_CODE': {
|
||||
return {
|
||||
...state,
|
||||
code: action.payload,
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_EDITOR_SET_LANG': {
|
||||
return {
|
||||
...state,
|
||||
lang: action.payload,
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { combineReducers } from 'redux';
|
||||
import ui from './ui';
|
||||
import editor from './editor';
|
||||
import pretest from './pretest';
|
||||
import records from './records';
|
||||
|
||||
const reducer = combineReducers({
|
||||
ui,
|
||||
editor,
|
||||
pretest,
|
||||
records,
|
||||
});
|
||||
|
||||
export default reducer;
|
||||
@@ -0,0 +1,103 @@
|
||||
import uuid from 'uuid/v4';
|
||||
import _ from 'lodash';
|
||||
|
||||
const initialId = uuid();
|
||||
|
||||
export default function reducer(state = {
|
||||
counter: 1,
|
||||
current: initialId,
|
||||
tabs: [initialId],
|
||||
meta: {
|
||||
[initialId]: {
|
||||
id: initialId,
|
||||
title: '#1',
|
||||
},
|
||||
},
|
||||
data: {
|
||||
[initialId]: {
|
||||
id: initialId,
|
||||
title: '#1',
|
||||
input: '',
|
||||
output: '',
|
||||
},
|
||||
},
|
||||
}, 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 {
|
||||
...state,
|
||||
data: {
|
||||
...state.data,
|
||||
[id]: {
|
||||
...state.data[id],
|
||||
[type]: value,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
export default function reducer(state = {
|
||||
rows: [],
|
||||
items: {},
|
||||
}, action) {
|
||||
switch (action.type) {
|
||||
case 'SCRATCHPAD_RECORDS_LOAD_SUBMISSIONS_FULFILLED': {
|
||||
const { rdocs } = action.payload;
|
||||
return {
|
||||
...state,
|
||||
rows: _.map(rdocs, '_id'),
|
||||
items: _.keyBy(rdocs, '_id'),
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_RECORDS_PUSH': {
|
||||
const { rdoc } = action.payload;
|
||||
if (rdoc.uid !== UserContext.uid
|
||||
|| rdoc.domain_id !== UserContext.domain
|
||||
|| rdoc.pid !== Context.problemId
|
||||
) {
|
||||
return state;
|
||||
}
|
||||
return {
|
||||
...state,
|
||||
rows: [rdoc._id, ...state.rows],
|
||||
items: {
|
||||
...state.items,
|
||||
[rdoc._id]: rdoc,
|
||||
},
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import Notification from 'vj/components/notification';
|
||||
|
||||
export default function reducer(state = {
|
||||
main: {
|
||||
size: '50%',
|
||||
},
|
||||
pretest: {
|
||||
visible: false,
|
||||
size: 200,
|
||||
},
|
||||
records: {
|
||||
visible: true,
|
||||
size: 200,
|
||||
isLoading: false,
|
||||
},
|
||||
isPosting: false,
|
||||
}, action) {
|
||||
switch (action.type) {
|
||||
case 'SCRATCHPAD_UI_CHANGE_SIZE': {
|
||||
const { uiElement, size } = action.payload;
|
||||
return {
|
||||
...state,
|
||||
[uiElement]: {
|
||||
...state[uiElement],
|
||||
size,
|
||||
},
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_UI_SET_VISIBILITY': {
|
||||
const { uiElement, visibility } = action.payload;
|
||||
return {
|
||||
...state,
|
||||
[uiElement]: {
|
||||
...state[uiElement],
|
||||
visible: visibility,
|
||||
},
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_UI_TOGGLE_VISIBILITY': {
|
||||
const { uiElement } = action.payload;
|
||||
return {
|
||||
...state,
|
||||
[uiElement]: {
|
||||
...state[uiElement],
|
||||
visible: !state[uiElement].visible,
|
||||
},
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_POST_PRETEST_PENDING':
|
||||
case 'SCRATCHPAD_POST_SUBMIT_PENDING': {
|
||||
return {
|
||||
...state,
|
||||
isPosting: true,
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_POST_PRETEST_FULFILLED':
|
||||
case 'SCRATCHPAD_POST_SUBMIT_FULFILLED': {
|
||||
return {
|
||||
...state,
|
||||
isPosting: false,
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_POST_PRETEST_REJECTED':
|
||||
case 'SCRATCHPAD_POST_SUBMIT_REJECTED': {
|
||||
Notification.error(action.payload.message);
|
||||
return {
|
||||
...state,
|
||||
isPosting: false,
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_RECORDS_LOAD_SUBMISSIONS_PENDING': {
|
||||
return {
|
||||
...state,
|
||||
records: {
|
||||
...state.records,
|
||||
isLoading: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_RECORDS_LOAD_SUBMISSIONS_REJECTED': {
|
||||
Notification.error(action.payload.message);
|
||||
return {
|
||||
...state,
|
||||
records: {
|
||||
...state.records,
|
||||
isLoading: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_RECORDS_LOAD_SUBMISSIONS_FULFILLED': {
|
||||
return {
|
||||
...state,
|
||||
records: {
|
||||
...state.records,
|
||||
isLoading: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user