mirror of
https://github.com/SableClient/Sable.git
synced 2026-12-03 15:22:22 -08:00
only delete specific parent-child room mapping updates
This commit is contained in:
1 parent
df1826850d
commit
537efcc7c4
1 file changed
+22
-1
@@ -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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user