Fix first widget is now removed upon clicking Cancel
This commit is contained in:
@@ -13,14 +13,44 @@ import { v4 as uuid } from 'uuid';
|
||||
|
||||
export default function Home({...props}) {
|
||||
// deconstructing props
|
||||
const { view, layout, setLayout, setOriginalLayout, onLayoutChange, onChangeView, onCancel,
|
||||
isDelete, setIsDelete, isEditable, setIsEditable, widgetArray, setWidgetArray } = props;
|
||||
const { view, layout, setLayout, setOriginalLayout, onLayoutChange, onChangeView, onCancel,
|
||||
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) => {
|
||||
// setLayout(prev => [
|
||||
// ...prev,
|
||||
// {
|
||||
// i: ID,
|
||||
// x: (prev.length * 3) % 12,
|
||||
// y: Infinity,
|
||||
// w: w,
|
||||
// h: h,
|
||||
// minW: minw,
|
||||
// minH: minh,
|
||||
// maxW: maxw,
|
||||
// maxH: maxh,
|
||||
// static: false,
|
||||
// resizeHandles: ['se']
|
||||
// }
|
||||
// ]);
|
||||
// onEditWidgets();
|
||||
// };
|
||||
|
||||
function appendWidget(name, w, h, minw, minh, maxw, maxh) {
|
||||
beginEditIfNeeded(); // Save state before anything else
|
||||
|
||||
const newID = uuid(); // could be replaced with something else like guid
|
||||
|
||||
setWidgetArray([ // updating widget array containing info on the types of widgets
|
||||
...widgetArray,
|
||||
{i: newID, widget: name }
|
||||
]);
|
||||
// onAddWidget(newID, w, h, minw, minh, maxw, maxh); // updating array containing info on layout of widgets
|
||||
|
||||
setLayout(prev => [
|
||||
...prev,
|
||||
{
|
||||
i: ID,
|
||||
i: newID,
|
||||
x: (prev.length * 3) % 12,
|
||||
y: Infinity,
|
||||
w: w,
|
||||
@@ -31,18 +61,8 @@ export default function Home({...props}) {
|
||||
maxH: maxh,
|
||||
static: false,
|
||||
resizeHandles: ['se']
|
||||
}
|
||||
},
|
||||
]);
|
||||
onEditWidgets();
|
||||
};
|
||||
|
||||
function appendWidget(name, w, h, minw, minh, maxw, maxh) {
|
||||
const newID = uuid(); // could be replaced with something else like guid
|
||||
setWidgetArray([ // updating widget array containing info on the types of widgets
|
||||
...widgetArray,
|
||||
{i: newID, widget: name }
|
||||
]);
|
||||
onAddWidget(newID, w, h, minw, minh, maxw, maxh); // updating array containing info on layout of widgets
|
||||
}
|
||||
|
||||
const onEditWidgets = () => {
|
||||
@@ -70,6 +90,7 @@ export default function Home({...props}) {
|
||||
setIsEditable(false);
|
||||
setIsDelete(false);
|
||||
setOriginalLayout([]); // Clear backup layout
|
||||
setOriginalWidgets([]);
|
||||
}
|
||||
|
||||
const onDeleteWidgets = () => {
|
||||
@@ -98,7 +119,7 @@ export default function Home({...props}) {
|
||||
}
|
||||
|
||||
// Prop Forwarding
|
||||
const MyDashboardProps = { layout, onLayoutChange, isEditable, isDelete, DeleteWidget, widgetArray, appendWidget };
|
||||
const MyDashboardProps = { layout, onLayoutChange, isEditable, beginEditIfNeeded, isDelete, DeleteWidget, widgetArray, appendWidget };
|
||||
const settingsButtonProps = { onEditWidgets, onDeleteWidgets, appendWidget };
|
||||
|
||||
return (
|
||||
|
||||
@@ -26,7 +26,7 @@ export default function MyDashboard({layout, onLayoutChange, isEditable, isDelet
|
||||
};
|
||||
|
||||
// Show large 'Add Widget' button when dashboard is empty
|
||||
if ( !widgetArray.length ) {
|
||||
if ( !layout.length ) {
|
||||
return (
|
||||
<Flex
|
||||
align="center"
|
||||
|
||||
Reference in New Issue
Block a user