ui: enhance scratchpad language select

This commit is contained in:
undefined committed 2022-03-02 13:44:07 +08:00
1 parent 3034f5ec79
commit ae7857a79c
5 files changed
+43 -31

No files matched your search

@@ -2,24 +2,22 @@ let cacheKey = `${UserContext._id}/${UiContext.pdoc.domainId}/${UiContext.pdoc.d
if (UiContext.tdoc?._id && UiContext.tdoc.rule !== 'homework') cacheKey += `@${UiContext.tdoc._id}`;
export default function reducer(state = {
lang: UiContext.codeLang,
lang: localStorage.getItem(`${cacheKey}#lang`) || UiContext.codeLang,
code: localStorage.getItem(cacheKey) || UiContext.codeTemplate,
}, action) {
switch (action.type) {
case 'SCRATCHPAD_EDITOR_UPDATE_CODE': {
if (action.type === 'SCRATCHPAD_EDITOR_UPDATE_CODE') {
localStorage.setItem(cacheKey, action.payload);
return {
...state,
code: action.payload,
};
}
case 'SCRATCHPAD_EDITOR_SET_LANG': {
if (action.type === 'SCRATCHPAD_EDITOR_SET_LANG') {
localStorage.setItem(`${cacheKey}#lang`, action.payload);
return {
...state,
lang: action.payload,
};
}
default:
return state;
}
return state;
}