ui: save editor state to localstorage

This commit is contained in:
undefined committed 2021-05-22 13:24:21 +08:00
1 parent 41110dde90
commit 9b9243a87c
2 files changed
+17 -16

No files matched your search

@@ -1,21 +1,22 @@
export default function reducer(state = { export default function reducer(state = {
lang: UiContext.codeLang, lang: UiContext.codeLang,
code: UiContext.codeTemplate, code: localStorage.getItem(`${UiContext.pdoc.domainId}/${UiContext.pdoc.docId}`) || UiContext.codeTemplate,
}, action) { }, action) {
switch (action.type) { switch (action.type) {
case 'SCRATCHPAD_EDITOR_UPDATE_CODE': { case 'SCRATCHPAD_EDITOR_UPDATE_CODE': {
return { localStorage.setItem(`${UiContext.pdoc.domainId}/${UiContext.pdoc.docId}`, action.payload);
...state, return {
code: action.payload, ...state,
}; code: action.payload,
} };
case 'SCRATCHPAD_EDITOR_SET_LANG': { }
return { case 'SCRATCHPAD_EDITOR_SET_LANG': {
...state, return {
lang: action.payload, ...state,
}; lang: action.payload,
} };
default: }
return state; default:
return state;
} }
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/ui-default", "name": "@hydrooj/ui-default",
"version": "4.8.38", "version": "4.8.39",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "hydro.js", "main": "hydro.js",