Skip to content

Commit

Permalink
refactor: flush containsActiveZone when child zones removed
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Dec 27, 2024
1 parent 4eb39ff commit 681d61c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/core/components/DraggableComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -490,6 +508,7 @@ export const DraggableComponent = ({
index,
depth: depth + 1,
registerLocalZone,
unregisterLocalZone,
path: [...path, id],
}}
>
Expand Down
1 change: 1 addition & 0 deletions packages/core/components/DropZone/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type DropZoneContext<UserConfig extends Config = Config> = {
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;
Expand Down
5 changes: 5 additions & 0 deletions packages/core/components/DropZone/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function DropZoneEdit({
registerZoneArea,
depth,
registerLocalZone,
unregisterLocalZone,
deepestZone = rootDroppableId,
deepestArea,
nextDeepestArea,
Expand Down Expand Up @@ -93,6 +94,10 @@ function DropZoneEdit({
}

return () => {
if (unregisterLocalZone) {
unregisterLocalZone(zoneCompound);
}

if (ctx?.unregisterZone) {
ctx?.unregisterZone(zoneCompound);
}
Expand Down

0 comments on commit 681d61c

Please sign in to comment.