Fix layout of newly added Widgets

This commit is contained in:
Daniel S. Hansen
2025-08-11 14:53:17 -07:00
parent 77bba49dc8
commit cab0fe3a0b
2 changed files with 9 additions and 4 deletions
+7 -2
View File
@@ -40,6 +40,9 @@ export default function Home({...props}) {
beginEditIfNeeded(); // Save state before anything else beginEditIfNeeded(); // Save state before anything else
const newID = uuid(); // could be replaced with something else like guid const newID = uuid(); // could be replaced with something else like guid
const COLS = 16;
const W = w ?? 3;
const H = h ?? 3;
setWidgetArray([ // updating widget array containing info on the types of widgets setWidgetArray([ // updating widget array containing info on the types of widgets
...widgetArray, ...widgetArray,
@@ -51,8 +54,10 @@ export default function Home({...props}) {
...prev, ...prev,
{ {
i: newID, i: newID,
x: (prev.length * 3) % 12, // x: (prev.length * 3) % 12,
y: Infinity, // y: Infinity,
x: (prev.length * W) % COLS,
y: 0,
w: w, w: w,
h: h, h: h,
minW: minw, minW: minw,
@@ -48,7 +48,7 @@ export default function MyDashboard({layout, onLayoutChange, isEditable, isDelet
useCSSTransforms={false} // remove the sliding animation of the widgets useCSSTransforms={false} // remove the sliding animation of the widgets
className="layout" className="layout"
layout={layout} layout={layout}
cols={15} // Total columns in grid cols={16} // Total columns in grid
rowHeight={30} // Height of a single row in px rowHeight={30} // Height of a single row in px
isBounded={true} // Total width of the grid isBounded={true} // Total width of the grid
margin={[15, 5]} // [horizontal, vertical] gap margin={[15, 5]} // [horizontal, vertical] gap