Refactor onSave and onCancel to track both layout and widgetArray useState() in order to restore state on cancel
This commit is contained in:
@@ -13,7 +13,7 @@ import { v4 as uuid } from 'uuid';
|
|||||||
|
|
||||||
export default function Home({...props}) {
|
export default function Home({...props}) {
|
||||||
// deconstructing 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;
|
isDelete, setIsDelete, beginEditIfNeeded, isEditable, setIsEditable, widgetArray, setWidgetArray } = props;
|
||||||
|
|
||||||
// const onAddWidget = (ID, w, h, minw, minh, maxw, maxh) => {
|
// const onAddWidget = (ID, w, h, minw, minh, maxw, maxh) => {
|
||||||
|
|||||||
@@ -19,9 +19,8 @@ export default function Dashboard() {
|
|||||||
|
|
||||||
const beginEditIfNeeded = () => {
|
const beginEditIfNeeded = () => {
|
||||||
if ( !isEditable ) {
|
if ( !isEditable ) {
|
||||||
// Save deep copies to preserve state
|
setOriginalLayout(layout);
|
||||||
setOriginalLayout(structuredClone(layout));
|
setOriginalWidgets(widgetArray);
|
||||||
setOriginalWidgets(structuredClone(widgetArray));
|
|
||||||
setIsEditable(true);
|
setIsEditable(true);
|
||||||
setIsDelete(false);
|
setIsDelete(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user