fix: new sections without add and change listeners (#1230)
This commit is contained in:
@@ -195,6 +195,32 @@ export const useGridstack = (section: Omit<Section, "items">, itemIds: string[])
|
|||||||
[moveItemToSection, moveInnerSectionToSection, section.id],
|
[moveItemToSection, moveInnerSectionToSection, section.id],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// initialize the gridstack
|
||||||
|
useEffect(() => {
|
||||||
|
const isReady = initializeGridstack({
|
||||||
|
section,
|
||||||
|
itemIds,
|
||||||
|
refs: {
|
||||||
|
items: itemRefs,
|
||||||
|
wrapper: wrapperRef,
|
||||||
|
gridstack: gridRef,
|
||||||
|
},
|
||||||
|
sectionColumnCount: columnCount,
|
||||||
|
});
|
||||||
|
|
||||||
|
// If the section is ready mark it as ready
|
||||||
|
// When all sections are ready the board is ready and will get visible
|
||||||
|
if (isReady) {
|
||||||
|
markAsReady(section.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only run this effect when the section items change
|
||||||
|
}, [itemIds.length, columnCount]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IMPORTANT: This effect has to be placed after the effect to initialize the gridstack
|
||||||
|
* because we need the gridstack object to add the listeners
|
||||||
|
*/
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isEditMode) return;
|
if (!isEditMode) return;
|
||||||
const currentGrid = gridRef.current;
|
const currentGrid = gridRef.current;
|
||||||
@@ -231,28 +257,6 @@ export const useGridstack = (section: Omit<Section, "items">, itemIds: string[])
|
|||||||
};
|
};
|
||||||
}, [isEditMode, onAdd, onChange]);
|
}, [isEditMode, onAdd, onChange]);
|
||||||
|
|
||||||
// initialize the gridstack
|
|
||||||
useEffect(() => {
|
|
||||||
const isReady = initializeGridstack({
|
|
||||||
section,
|
|
||||||
itemIds,
|
|
||||||
refs: {
|
|
||||||
items: itemRefs,
|
|
||||||
wrapper: wrapperRef,
|
|
||||||
gridstack: gridRef,
|
|
||||||
},
|
|
||||||
sectionColumnCount: columnCount,
|
|
||||||
});
|
|
||||||
|
|
||||||
// If the section is ready mark it as ready
|
|
||||||
// When all sections are ready the board is ready and will get visible
|
|
||||||
if (isReady) {
|
|
||||||
markAsReady(section.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only run this effect when the section items change
|
|
||||||
}, [itemIds.length, columnCount]);
|
|
||||||
|
|
||||||
const sectionHeight = section.kind === "dynamic" && "height" in section ? (section.height as number) : null;
|
const sectionHeight = section.kind === "dynamic" && "height" in section ? (section.height as number) : null;
|
||||||
|
|
||||||
// We want the amount of rows in a dynamic section to be the height of the section in the outer gridstack
|
// We want the amount of rows in a dynamic section to be the height of the section in the outer gridstack
|
||||||
|
|||||||
Reference in New Issue
Block a user