Skip to content

Commit

Permalink
fix: 새로운 pages로 노드 업데이트하게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
djk01281 committed Nov 14, 2024
1 parent 974f504 commit a850f3e
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions frontend/src/components/canvas/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ function Flow({ className }: CanvasProps) {
}
const newNodes = [...nds];
newNodes[index] = {
...newNodes[index],
position: updatedNode.position,
selected: false,
...updatedNode,
selected: newNodes[index].selected,
};
return newNodes;
});
Expand Down Expand Up @@ -131,21 +130,19 @@ function Flow({ className }: CanvasProps) {
const pageId = page.id.toString();
const existingNode = nodesMap.get(pageId) as Node | undefined;

if (!existingNode) {
const newNode = {
id: pageId,
type: "note",
data: { title: page.title, id: page.id },
position: {
x: Math.random() * 500,
y: Math.random() * 500,
},
selected: false,
};

nodesMap.set(pageId, newNode);
existingPageIds.current.add(pageId);
}
const newNode = {
id: pageId,
type: "note",
data: { title: page.title, id: page.id },
position: existingNode?.position || {
x: Math.random() * 500,
y: Math.random() * 500,
},
selected: false,
};

nodesMap.set(pageId, newNode);
existingPageIds.current.add(pageId);
});
}, [pages, ydoc]);

Expand Down

0 comments on commit a850f3e

Please sign in to comment.