mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
ui: migrate scratchpad drafts to IndexedDB
This commit is contained in:
1 parent
c25c1d5e89
commit
86d2a36731
3 files changed
+57
-21
No files matched your search
@@ -1,24 +1,9 @@
|
||||
let cacheKey = `${UserContext._id}/${UiContext.pdoc.domainId}/${UiContext.pdoc.docId}`;
|
||||
if (UiContext.tdoc?._id) cacheKey += `@${UiContext.tdoc._id}`;
|
||||
|
||||
// TODO switch to indexeddb
|
||||
export default function reducer(state = {
|
||||
lang: localStorage.getItem(`${cacheKey}#lang`) || UiContext.codeLang,
|
||||
code: localStorage.getItem(cacheKey) || UiContext.codeTemplate,
|
||||
lang: UiContext.codeLang,
|
||||
code: 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,
|
||||
};
|
||||
}
|
||||
if (action.type === 'SCRATCHPAD_EDITOR_HYDRATE') return action.payload;
|
||||
if (action.type === 'SCRATCHPAD_EDITOR_UPDATE_CODE') return { ...state, code: action.payload };
|
||||
if (action.type === 'SCRATCHPAD_EDITOR_SET_LANG') return { ...state, lang: action.payload };
|
||||
return state;
|
||||
}
|
||||
Reference in new issue
Block a user