Page Layout - Addition of widgets (#14184)
https://github.com/user-attachments/assets/130f12d7-5cef-4b83-912f-a9d42241f69f ~~This could be considered a POC 😅~~ addressing - https://github.com/twentyhq/core-team-issues/issues/1400 https://github.com/twentyhq/core-team-issues/issues/1403
This commit is contained in:
+32
@@ -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 };
|
||||
};
|
||||
Reference in New Issue
Block a user