ui: switch storage to indexeddb

This commit is contained in:
undefined committed 2024-07-03 18:10:40 +08:00
1 parent 70872fe931
commit c996bbfe6d
6 files changed
+102 -42

No files matched your search

@@ -1,6 +1,7 @@
let cacheKey = `${UserContext._id}/${UiContext.pdoc.domainId}/${UiContext.pdoc.docId}`;
if (UiContext.tdoc?._id && UiContext.tdoc.rule !== 'homework') 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,
@@ -54,6 +54,10 @@ export default class Sock {
onclose: (code: number, reason: string) => void;
onopen: (sock: ReconnectingWebSocket) => void;
on(event: 'message' | 'close' | 'open', callback: (...args: any[]) => void) {
this[`on${event}`] = callback;
}
send(data) {
this.sock.send(data);
}