nitin
2025-09-02 15:50:28 +05:30
committed by GitHub
parent 04d4c07b69
commit 1b2f079359
71 changed files with 2696 additions and 541 deletions
@@ -0,0 +1,32 @@
import { type Layout, type Layouts } from 'react-grid-layout';
import { useRecoilCallback } from 'recoil';
import { pageLayoutCurrentLayoutsState } from '../states/pageLayoutCurrentLayoutsState';
import { pageLayoutDraftState } from '../states/pageLayoutDraftState';
import { pageLayoutWidgetsState } from '../states/pageLayoutWidgetsState';
import { convertLayoutsToWidgets } from '../utils/convertLayoutsToWidgets';
export const usePageLayoutHandleLayoutChange = () => {
const handleLayoutChange = useRecoilCallback(
({ snapshot, set }) =>
(_: Layout[], allLayouts: Layouts) => {
set(pageLayoutCurrentLayoutsState, allLayouts);
const pageLayoutWidgets = snapshot
.getLoadable(pageLayoutWidgetsState)
.getValue();
const updatedWidgets = convertLayoutsToWidgets(
pageLayoutWidgets,
allLayouts,
);
set(pageLayoutDraftState, (prev) => ({
...prev,
widgets: updatedWidgets,
}));
},
[],
);
return { handleLayoutChange };
};