Skip to content

Commit 3d4adb6

Browse files
committed
update delete room action
1 parent bd0ddcc commit 3d4adb6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/context/reducers/roomsReducer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ export function roomsReducer(state: RoomProps[], action: CommtContextActions) {
2323
}
2424

2525
case "DELETE_ROOM": {
26-
const chatRoomAuthId = action.payload;
27-
return state.filter((room) => room.chatRoomAuthId !== chatRoomAuthId);
26+
const rooms = [...state];
27+
const roomIndexToBeDeleted = rooms.findIndex(
28+
(r) => r.chatRoomAuthId === action.payload,
29+
); // action.payload represents the chatRoomAuthId of the room to be deleted from the state
30+
rooms.splice(roomIndexToBeDeleted, 1); // Delete that particular index from the instance of the rooms
31+
32+
return rooms;
2833
}
2934

3035
case "UPDATE_LAST_MESSAGE": {

0 commit comments

Comments
 (0)