From a850f3e66fef11427779b615427b2289c5529d8e Mon Sep 17 00:00:00 2001 From: djk01281 Date: Thu, 14 Nov 2024 17:21:03 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=83=88=EB=A1=9C=EC=9A=B4=20pages?= =?UTF-8?q?=EB=A1=9C=20=EB=85=B8=EB=93=9C=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=ED=95=98=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/canvas/index.tsx | 33 +++++++++++------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/canvas/index.tsx b/frontend/src/components/canvas/index.tsx index 6f8cd390..cec8cf71 100644 --- a/frontend/src/components/canvas/index.tsx +++ b/frontend/src/components/canvas/index.tsx @@ -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; }); @@ -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]);