From 77bba49dc88e337af4787c264256ff350239c700 Mon Sep 17 00:00:00 2001 From: "Daniel S. Hansen" Date: Mon, 11 Aug 2025 14:40:05 -0700 Subject: [PATCH] Refactor onSave and onCancel to track both layout and widgetArray useState() in order to restore state on cancel --- client/src/components/Canvas/views/Home.jsx | 2 +- client/src/components/Dashboard.jsx | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/client/src/components/Canvas/views/Home.jsx b/client/src/components/Canvas/views/Home.jsx index 921b0e0..2516a76 100644 --- a/client/src/components/Canvas/views/Home.jsx +++ b/client/src/components/Canvas/views/Home.jsx @@ -13,7 +13,7 @@ import { v4 as uuid } from 'uuid'; export default function Home({...props}) { // deconstructing props - const { view, layout, setLayout, setOriginalLayout, onLayoutChange, onChangeView, onCancel, + const { view, layout, setLayout, setOriginalLayout, onLayoutChange, onChangeView, onCancel, setOriginalWidgets, isDelete, setIsDelete, beginEditIfNeeded, isEditable, setIsEditable, widgetArray, setWidgetArray } = props; // const onAddWidget = (ID, w, h, minw, minh, maxw, maxh) => { diff --git a/client/src/components/Dashboard.jsx b/client/src/components/Dashboard.jsx index c6667ea..a8dc9d5 100644 --- a/client/src/components/Dashboard.jsx +++ b/client/src/components/Dashboard.jsx @@ -19,9 +19,8 @@ export default function Dashboard() { const beginEditIfNeeded = () => { if ( !isEditable ) { - // Save deep copies to preserve state - setOriginalLayout(structuredClone(layout)); - setOriginalWidgets(structuredClone(widgetArray)); + setOriginalLayout(layout); + setOriginalWidgets(widgetArray); setIsEditable(true); setIsDelete(false); }