Fix cytoscapeStore: preserve positions, guard access, remove redundant write
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -64,7 +64,6 @@ export const useCytoscapeStore = defineStore('cytoscapeStore', {
|
|||||||
} else {
|
} else {
|
||||||
this.nodePositions[this.currentGraphId][direction]
|
this.nodePositions[this.currentGraphId][direction]
|
||||||
.push({ id: nodeId, position: position });
|
.push({ id: nodeId, position: position });
|
||||||
localStorage.setItem(SAVE_KEY_NAME, JSON.stringify(this.nodePositions));
|
|
||||||
}
|
}
|
||||||
this.savePositionsToStorage();
|
this.savePositionsToStorage();
|
||||||
},
|
},
|
||||||
@@ -73,6 +72,7 @@ export const useCytoscapeStore = defineStore('cytoscapeStore', {
|
|||||||
* @param {string} direction - Layout direction ('TB' or 'LR').
|
* @param {string} direction - Layout direction ('TB' or 'LR').
|
||||||
*/
|
*/
|
||||||
loadPositionsFromStorage(direction: string) {
|
loadPositionsFromStorage(direction: string) {
|
||||||
|
if (!this.nodePositions[this.currentGraphId]) return;
|
||||||
try {
|
try {
|
||||||
const raw = localStorage.getItem(SAVE_KEY_NAME);
|
const raw = localStorage.getItem(SAVE_KEY_NAME);
|
||||||
if (raw) {
|
if (raw) {
|
||||||
@@ -94,12 +94,9 @@ export const useCytoscapeStore = defineStore('cytoscapeStore', {
|
|||||||
},
|
},
|
||||||
setCurrentGraphId(currentGraphId: string) {
|
setCurrentGraphId(currentGraphId: string) {
|
||||||
this.currentGraphId = currentGraphId;
|
this.currentGraphId = currentGraphId;
|
||||||
this.nodePositions = {
|
if (!this.nodePositions[currentGraphId]) {
|
||||||
[this.currentGraphId]: {
|
this.nodePositions[currentGraphId] = { TB: [], LR: [] };
|
||||||
'TB': [],
|
}
|
||||||
'LR': [],
|
|
||||||
}
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user