feat: migrate graph snapshot handling to localStorage for improved persistence
All checks were successful
On Push to Main / test (push) Successful in 39s
On Push to Main / publish (push) Successful in 1m7s
On Push to Main / deploy-dev (push) Successful in 1m36s

This commit is contained in:
RaymondVerhoef
2026-05-27 20:27:16 +02:00
parent 9fb22b8090
commit 47a738fde3
2 changed files with 44 additions and 35 deletions

View File

@@ -52,11 +52,10 @@ export function useGraphData() {
// On mount, check whether a snapshot from a previous session exists.
useEffect(() => {
db.getGraphSnapshot().then(snap => {
if (snap?.ts) {
setSnapshotMeta({ ts: snap.ts, topicCount: snap.topicCount, relationCount: snap.relationCount });
}
});
const snap = db.getGraphSnapshot();
if (snap?.ts) {
setSnapshotMeta({ ts: snap.ts, topicCount: snap.topicCount, relationCount: snap.relationCount });
}
}, []);
// ── Single-topic mutations ───────────────────────────────────────────────────
@@ -124,7 +123,7 @@ export function useGraphData() {
*/
const bulkSave = useCallback(async (newTopics, newRelations) => {
// Persist a rollback point of the state we are about to overwrite.
await db.saveGraphSnapshot(topicsRef.current, relationsRef.current);
db.saveGraphSnapshot(topicsRef.current, relationsRef.current);
setSnapshotMeta({
ts: Date.now(),
topicCount: topicsRef.current.length,
@@ -145,7 +144,7 @@ export function useGraphData() {
* Returns true on success, false if no snapshot exists.
*/
const restoreSnapshot = useCallback(async () => {
const snap = await db.getGraphSnapshot();
const snap = db.getGraphSnapshot();
if (!snap?.topics) return false;
// Apply without taking a new snapshot — we don't want to overwrite
@@ -155,7 +154,7 @@ export function useGraphData() {
setTopics(snap.topics);
setRelations(snap.relations);
await db.clearGraphSnapshot();
db.clearGraphSnapshot();
setSnapshotMeta(null);
return true;
}, []);