Fix toolbox persistence, table evaluation, and onboarding panel styling
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
This commit is contained in:
parent
0171c9fc98
commit
184314d913
9 changed files with 119 additions and 32 deletions
|
|
@ -11,7 +11,8 @@ import {
|
|||
setLinks as dbSetLinks,
|
||||
setModuleData as dbSetModuleData,
|
||||
setSetting as dbSetSetting,
|
||||
setToolboxes as dbSetToolboxes
|
||||
setToolboxes as dbSetToolboxes,
|
||||
setToolboxSnapshot as dbSetToolboxSnapshot
|
||||
} from "../../../utils/indexedDbStorage.js";
|
||||
import {
|
||||
compactToolboxesForStorage,
|
||||
|
|
@ -38,6 +39,8 @@ export function useIndexedToolboxes(onError) {
|
|||
const toolboxesRef = useRef(toolboxes);
|
||||
const linksRef = useRef(links);
|
||||
const moduleDataRef = useRef(moduleData);
|
||||
const confirmedModuleDataRef = useRef(moduleData);
|
||||
const moduleWriteQueuesRef = useRef({});
|
||||
const toastPositionRef = useRef(toastPosition);
|
||||
const writeVersionsRef = useRef({
|
||||
toolboxes: 0,
|
||||
|
|
@ -94,7 +97,9 @@ export function useIndexedToolboxes(onError) {
|
|||
if (cancelled) return;
|
||||
commitToolboxes((Array.isArray(storedToolboxes) ? storedToolboxes : []).map(normalizeToolbox).filter(Boolean));
|
||||
commitLinks(storedLinks && typeof storedLinks === "object" ? storedLinks : {});
|
||||
commitModuleData(Object.fromEntries((storedModules || []).map((entry) => [entry.key, entry.data])));
|
||||
const loadedModuleData = Object.fromEntries((storedModules || []).map((entry) => [entry.key, entry.data]));
|
||||
confirmedModuleDataRef.current = loadedModuleData;
|
||||
commitModuleData(loadedModuleData);
|
||||
commitToastPosition(storedToastPosition === "left" ? "left" : "right");
|
||||
setReady(true);
|
||||
refreshQuota();
|
||||
|
|
@ -148,11 +153,22 @@ export function useIndexedToolboxes(onError) {
|
|||
writeVersionsRef.current.moduleDataByKey = commitModuleDataCheckpoints(writeVersionsRef.current.moduleDataByKey, [checkpoint]);
|
||||
const nextModuleData = applyModuleDataValue(moduleDataRef.current, key, compact);
|
||||
commitModuleData(nextModuleData);
|
||||
const operation = compact == null ? dbRemoveModuleData(key) : dbSetModuleData(key, compact);
|
||||
operation.then(refreshQuota).catch((error) => {
|
||||
commitModuleData(rollbackModuleDataCheckpoints(moduleDataRef.current, writeVersionsRef.current.moduleDataByKey, [checkpoint]));
|
||||
const previousQueue = moduleWriteQueuesRef.current[key] || Promise.resolve();
|
||||
const operation = previousQueue.catch(() => {}).then(async () => {
|
||||
if (compact == null) await dbRemoveModuleData(key);
|
||||
else await dbSetModuleData(key, compact);
|
||||
confirmedModuleDataRef.current = applyModuleDataValue(confirmedModuleDataRef.current, key, compact);
|
||||
await refreshQuota();
|
||||
}).catch((error) => {
|
||||
if (moduleDataRef.current[key] === compact) {
|
||||
commitModuleData(applyModuleDataValue(moduleDataRef.current, key, confirmedModuleDataRef.current[key]));
|
||||
}
|
||||
reportStorageError(error);
|
||||
});
|
||||
const queuedOperation = operation.finally(() => {
|
||||
if (moduleWriteQueuesRef.current[key] === queuedOperation) delete moduleWriteQueuesRef.current[key];
|
||||
});
|
||||
moduleWriteQueuesRef.current[key] = queuedOperation;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -179,6 +195,30 @@ export function useIndexedToolboxes(onError) {
|
|||
});
|
||||
}
|
||||
|
||||
async function persistToolboxSnapshot(nextToolboxes, nextLinks, nextModuleData) {
|
||||
const normalizedToolboxes = compactToolboxesForStorage(nextToolboxes).map(normalizeToolbox).filter(Boolean);
|
||||
const previous = {
|
||||
toolboxes: toolboxesRef.current,
|
||||
links: linksRef.current,
|
||||
moduleData: moduleDataRef.current
|
||||
};
|
||||
commitToolboxes(normalizedToolboxes);
|
||||
commitLinks(nextLinks);
|
||||
commitModuleData(nextModuleData);
|
||||
try {
|
||||
await dbSetToolboxSnapshot(compactToolboxesForStorage(normalizedToolboxes), nextLinks, nextModuleData);
|
||||
confirmedModuleDataRef.current = nextModuleData;
|
||||
await refreshQuota();
|
||||
return true;
|
||||
} catch (error) {
|
||||
commitToolboxes(previous.toolboxes);
|
||||
commitLinks(previous.links);
|
||||
commitModuleData(previous.moduleData);
|
||||
reportStorageError(error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function setToastPosition(position) {
|
||||
const normalized = position === "left" ? "left" : "right";
|
||||
const previousToastPosition = toastPositionRef.current;
|
||||
|
|
@ -206,6 +246,7 @@ export function useIndexedToolboxes(onError) {
|
|||
removeModuleData,
|
||||
removeToolboxModuleData,
|
||||
setToastPosition,
|
||||
refreshQuota
|
||||
refreshQuota,
|
||||
persistToolboxSnapshot
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue