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.
24 lines
772 B
TypeScript
24 lines
772 B
TypeScript
let cacheKey = `${UserContext._id}/${UiContext.pdoc.domainId}/${UiContext.pdoc.docId}`;
|
|
if (UiContext.tdoc?._id && UiContext.tdoc.rule !== 'homework') cacheKey += `@${UiContext.tdoc._id}`;
|
|
|
|
export default function reducer(state = {
|
|
lang: localStorage.getItem(`${cacheKey}#lang`) || UiContext.codeLang,
|
|
code: localStorage.getItem(cacheKey) || UiContext.codeTemplate,
|
|
}, action: any = {}) {
|
|
if (action.type === 'SCRATCHPAD_EDITOR_UPDATE_CODE') {
|
|
localStorage.setItem(cacheKey, action.payload);
|
|
return {
|
|
...state,
|
|
code: action.payload,
|
|
};
|
|
}
|
|
if (action.type === 'SCRATCHPAD_EDITOR_SET_LANG') {
|
|
localStorage.setItem(`${cacheKey}#lang`, action.payload);
|
|
return {
|
|
...state,
|
|
lang: action.payload,
|
|
};
|
|
}
|
|
return state;
|
|
}
|