Initialize nodePositions structure before nested access
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -45,6 +45,12 @@ export const useCytoscapeStore = defineStore('cytoscapeStore', {
|
||||
* @param {string} direction - Layout direction ('TB' or 'LR').
|
||||
*/
|
||||
saveNodePosition(nodeId: string, position: Position, direction: string) {
|
||||
if (!this.nodePositions[this.currentGraphId]) {
|
||||
this.nodePositions[this.currentGraphId] = {};
|
||||
}
|
||||
if (!this.nodePositions[this.currentGraphId][direction]) {
|
||||
this.nodePositions[this.currentGraphId][direction] = [];
|
||||
}
|
||||
// 若是資訊曾經存在這張圖於localStorage中
|
||||
if (localStorage.getItem(SAVE_KEY_NAME)) {
|
||||
const nodeToSave = this.nodePositions[this.currentGraphId][direction]
|
||||
@@ -56,7 +62,6 @@ export const useCytoscapeStore = defineStore('cytoscapeStore', {
|
||||
.push({ id: nodeId, position: position });
|
||||
}
|
||||
} else {
|
||||
this.nodePositions[this.currentGraphId][direction] = [];
|
||||
this.nodePositions[this.currentGraphId][direction]
|
||||
.push({ id: nodeId, position: position });
|
||||
localStorage.setItem(SAVE_KEY_NAME, JSON.stringify(this.nodePositions));
|
||||
|
||||
Reference in New Issue
Block a user