Skip to content

Commit 44ff5ca

Browse files
committed
Added delete room action to context
1 parent 89f744b commit 44ff5ca

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/context/actions/roomsActions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export const addRoom =
2424
dispatch({ type: "ADD_ROOM", payload: room });
2525
};
2626

27+
export const deleteRoom =
28+
(chatRoomAuthId: string) => (dispatch: Dispatch<CommtContextActions>) => {
29+
dispatch({ type: "DELETE_ROOM", payload: chatRoomAuthId });
30+
};
31+
2732
export const updateLastMessage =
2833
(data: UpdateLastMessageProps) =>
2934
(dispatch: Dispatch<CommtContextActions>) => {

src/context/reducers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const InitialState: CommtContextData = {
3939
type RoomsActions =
4040
| { type: "SET_ROOMS"; payload: RoomProps[] }
4141
| { type: "ADD_ROOM"; payload: RoomProps }
42+
| { type: "DELETE_ROOM"; payload: string }
4243
| { type: "UPDATE_LAST_MESSAGE"; payload: UpdateLastMessageProps }
4344
| { type: "UPDATE_READ_TOKEN"; payload: ReadTokenProps }
4445
| { type: "UPDATE_UNREAD_MSG_COUNT"; payload: UpdateUnreadMsgCountProps };

src/context/reducers/roomsReducer.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export function roomsReducer(state: RoomProps[], action: CommtContextActions) {
2222
return [...state, action.payload];
2323
}
2424

25+
case "DELETE_ROOM": {
26+
const chatRoomAuthId = action.payload;
27+
return state.filter((room) => room.chatRoomAuthId !== chatRoomAuthId);
28+
}
29+
2530
case "UPDATE_LAST_MESSAGE": {
2631
const { roomId, lastMessage } = action.payload;
2732
return state.map((room) =>

0 commit comments

Comments
 (0)