From 681d61cdb2aa69667291abb1ba408dcd1e340e3e Mon Sep 17 00:00:00 2001 From: Chris Villa Date: Fri, 27 Dec 2024 16:59:09 +0000 Subject: [PATCH] refactor: flush containsActiveZone when child zones removed --- .../components/DraggableComponent/index.tsx | 19 +++++++++++++++++++ packages/core/components/DropZone/context.tsx | 1 + packages/core/components/DropZone/index.tsx | 5 +++++ 3 files changed, 25 insertions(+) diff --git a/packages/core/components/DraggableComponent/index.tsx b/packages/core/components/DraggableComponent/index.tsx index 0dcb7071f2..46a2a1dc04 100644 --- a/packages/core/components/DraggableComponent/index.tsx +++ b/packages/core/components/DraggableComponent/index.tsx @@ -145,6 +145,24 @@ export const DraggableComponent = ({ [setLocalZones] ); + const unregisterLocalZone = useCallback( + (zoneCompound: string) => { + // Propagate local zone + ctx?.unregisterLocalZone?.(zoneCompound); + + setLocalZones((obj) => { + const newLocalZones = { + ...obj, + }; + + delete newLocalZones[zoneCompound]; + + return newLocalZones; + }); + }, + [setLocalZones] + ); + const containsActiveZone = Object.values(localZones).filter(Boolean).length > 0; @@ -490,6 +508,7 @@ export const DraggableComponent = ({ index, depth: depth + 1, registerLocalZone, + unregisterLocalZone, path: [...path, id], }} > diff --git a/packages/core/components/DropZone/context.tsx b/packages/core/components/DropZone/context.tsx index ca86b5a4dc..de408a2c91 100644 --- a/packages/core/components/DropZone/context.tsx +++ b/packages/core/components/DropZone/context.tsx @@ -30,6 +30,7 @@ export type DropZoneContext = { mode?: "edit" | "render"; depth: number; registerLocalZone?: (zone: string, active: boolean) => void; // A zone as it pertains to the current area + unregisterLocalZone?: (zone: string) => void; deepestZone?: string | null; deepestArea?: string | null; nextDeepestZone?: string | null; diff --git a/packages/core/components/DropZone/index.tsx b/packages/core/components/DropZone/index.tsx index 9fa3a3afa9..5d8245294e 100644 --- a/packages/core/components/DropZone/index.tsx +++ b/packages/core/components/DropZone/index.tsx @@ -65,6 +65,7 @@ function DropZoneEdit({ registerZoneArea, depth, registerLocalZone, + unregisterLocalZone, deepestZone = rootDroppableId, deepestArea, nextDeepestArea, @@ -93,6 +94,10 @@ function DropZoneEdit({ } return () => { + if (unregisterLocalZone) { + unregisterLocalZone(zoneCompound); + } + if (ctx?.unregisterZone) { ctx?.unregisterZone(zoneCompound); }