ui: migrate scratchpad drafts to IndexedDB

This commit is contained in:
undefined committed 2026-08-25 14:29:14 +00:00
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;
}