You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
2.6 KiB
TypeScript
112 lines
2.6 KiB
TypeScript
4 years ago
|
import Notification from 'vj/components/notification';
|
||
3 years ago
|
import i18n from 'vj/utils/i18n';
|
||
4 years ago
|
|
||
|
export default function reducer(state = {
|
||
|
main: {
|
||
|
size: '50%',
|
||
|
},
|
||
|
pretest: {
|
||
3 years ago
|
visible: ['default', 'fileio'].includes(UiContext.pdoc.config?.type)
|
||
|
? localStorage.getItem('scratchpad/pretest') === 'true'
|
||
|
: false,
|
||
4 years ago
|
size: 200,
|
||
|
},
|
||
|
records: {
|
||
3 years ago
|
visible: UiContext.canViewRecord && localStorage.getItem('scratchpad/records') === 'true',
|
||
3 years ago
|
size: 100,
|
||
4 years ago
|
isLoading: false,
|
||
|
},
|
||
|
isPosting: false,
|
||
|
}, action) {
|
||
|
switch (action.type) {
|
||
3 years ago
|
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;
|
||
3 years ago
|
localStorage.setItem(`scratchpad/${uiElement}`, visibility.toString());
|
||
3 years ago
|
return {
|
||
|
...state,
|
||
|
[uiElement]: {
|
||
|
...state[uiElement],
|
||
|
visible: visibility,
|
||
|
},
|
||
|
};
|
||
|
}
|
||
|
case 'SCRATCHPAD_UI_TOGGLE_VISIBILITY': {
|
||
|
const { uiElement } = action.payload;
|
||
3 years ago
|
localStorage.setItem(`scratchpad/${uiElement}`, (!state[uiElement].visible).toString());
|
||
3 years ago
|
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': {
|
||
|
Notification.success(i18n('Submitted.'));
|
||
3 years ago
|
if (action.type === 'SCRATCHPAD_POST_SUBMIT_FULFILLED') {
|
||
|
state.records.visible = true;
|
||
|
}
|
||
3 years ago
|
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;
|
||
4 years ago
|
}
|
||
|
}
|