feat: migrate graph snapshot handling to localStorage for improved persistence
This commit is contained in:
@@ -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;
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user