Skip to content

Commit

Permalink
WidgetLayout: remove conflicting data-grid prop from the widgets
Browse files Browse the repository at this point in the history
The same information is added by react-grid-layout via the 'layouts' prop
  • Loading branch information
maksis committed Oct 27, 2024
1 parent 950e86c commit c80cdf8
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions src/routes/Home/components/WidgetLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ const mapWidget = (
componentId={layoutItem.i!}
widgetInfo={widgetInfo}
settings={settings}
data-grid={layoutItem}
rootWidgetT={rootWidgetT}
/>
);
};

const WidgetLayout = React.memo(function WidgetLayout() {
const [breakpoint, setBreakpoint] = useState('lg');
const [initialLayoutUpdateFired, setInitialLayoutUpdateFired] = useState(false);

const { t } = useTranslation();
const rootWidgetT = getModuleT(
Expand All @@ -57,34 +55,27 @@ const WidgetLayout = React.memo(function WidgetLayout() {
const layouts = useStore<Layouts>(WidgetStore);

const widgets = React.useMemo(() => {
console.debug('WidgetLayout: layouts loaded', breakpoint);
// console.debug('WidgetLayout: layouts loaded', breakpoint, layouts[breakpoint]);
return layouts[breakpoint]
.map((w) => mapWidget(w, rootWidgetT))
.filter((widget) => widget);
}, [layouts, breakpoint]);

React.useEffect(() => console.log('RERENDER', breakpoint));
const onLayoutChanged = (layout: Layout[], layouts: Layouts) => {
//console.debug(
// 'WidgetLayout: saving layout',
// layout,
//);

WidgetStore.onLayoutChange(layout, layouts);
};

return (
<>
<ResponsiveReactGridLayout
className="ui cards layout"
rowHeight={50}
onLayoutChange={(layout, layouts) => {
// The initial render without correct breakpoint usually contains unwanted data
if (!initialLayoutUpdateFired) {
// console.debug('WidgetLayout: initial layout update fired');
setInitialLayoutUpdateFired(true);
return;
}

//console.debug(
// 'WidgetLayout: layout changed',
// JSON.stringify(layout, null, 2),
// breakpoint,
//);

WidgetStore.onLayoutChange(layout, layouts);
}}
onLayoutChange={onLayoutChanged}
onBreakpointChange={(bp) => {
// console.debug('WidgetLayout: breakpoint changed', bp);
setBreakpoint(bp);
Expand Down

0 comments on commit c80cdf8

Please sign in to comment.