only delete specific parent-child room mapping updates

This commit is contained in:
Evie Gauthier committed 2026-03-03 00:26:22 -05:00
1 parent df1826850d
commit 537efcc7c4
1 file changed
+22 -1
+22 -1
View File
@@ -28,6 +28,11 @@ export type RoomToParentsAction =
parent: string;
children: string[];
}
| {
type: 'REMOVE_CHILD';
parent: string;
child: string;
}
| {
type: 'DELETE';
roomId: string;
@@ -50,6 +55,22 @@ export const roomToParentsAtom = atom<RoomToParents, [RoomToParentsAction], unde
);
return;
}
if (action.type === 'REMOVE_CHILD') {
set(
baseRoomToParents,
produce(get(baseRoomToParents), (draftRoomToParents) => {
const parents = draftRoomToParents.get(action.child);
if (!parents) return;
parents.delete(action.parent);
if (parents.size === 0) {
draftRoomToParents.delete(action.child);
} else {
draftRoomToParents.set(action.child, parents);
}
})
);
return;
}
if (action.type === 'DELETE') {
set(
baseRoomToParents,
@@ -100,7 +121,7 @@ export const useBindRoomToParentsAtom = (
if (isValidChild(mEvent)) {
setRoomToParents({ type: 'PUT', parent: roomId, children: [childId] });
} else {
setRoomToParents({ type: 'DELETE', roomId: childId });
setRoomToParents({ type: 'REMOVE_CHILD', parent: roomId, child: childId });
}
}
}