2022-02-18 13:46:19 +00:00
|
|
|
import { TActionsRoom } from '../actions/room';
|
2020-03-06 13:13:24 +00:00
|
|
|
import { ROOM } from '../actions/actionsTypes';
|
|
|
|
|
2022-02-18 13:46:19 +00:00
|
|
|
export type IRoomRecord = string[];
|
|
|
|
|
|
|
|
export interface IRoom {
|
|
|
|
rid: string;
|
|
|
|
isDeleting: boolean;
|
|
|
|
rooms: IRoomRecord;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const initialState: IRoom = {
|
|
|
|
rid: '',
|
2020-04-30 17:53:35 +00:00
|
|
|
isDeleting: false,
|
|
|
|
rooms: []
|
2020-03-06 13:13:24 +00:00
|
|
|
};
|
|
|
|
|
2022-02-18 13:46:19 +00:00
|
|
|
export default function (state = initialState, action: TActionsRoom): IRoom {
|
2020-03-06 13:13:24 +00:00
|
|
|
switch (action.type) {
|
2020-04-30 17:53:35 +00:00
|
|
|
case ROOM.SUBSCRIBE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
rooms: [action.rid, ...state.rooms]
|
|
|
|
};
|
|
|
|
case ROOM.UNSUBSCRIBE:
|
|
|
|
return {
|
|
|
|
...state,
|
2021-09-13 20:41:05 +00:00
|
|
|
rooms: state.rooms.filter(rid => rid !== action.rid)
|
2020-04-30 17:53:35 +00:00
|
|
|
};
|
2020-03-20 16:38:01 +00:00
|
|
|
case ROOM.LEAVE:
|
2020-03-06 13:13:24 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2021-06-07 16:18:14 +00:00
|
|
|
rid: action.room.rid,
|
2020-03-06 13:13:24 +00:00
|
|
|
isDeleting: true
|
|
|
|
};
|
2020-03-20 16:38:01 +00:00
|
|
|
case ROOM.DELETE:
|
|
|
|
return {
|
|
|
|
...state,
|
2021-07-02 19:13:41 +00:00
|
|
|
rid: action.room.rid,
|
2020-03-20 16:38:01 +00:00
|
|
|
isDeleting: true
|
|
|
|
};
|
2020-05-08 17:36:10 +00:00
|
|
|
case ROOM.CLOSE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
rid: action.rid,
|
|
|
|
isDeleting: true
|
|
|
|
};
|
|
|
|
case ROOM.FORWARD:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
rid: action.rid,
|
|
|
|
isDeleting: true
|
|
|
|
};
|
2020-03-20 16:38:01 +00:00
|
|
|
case ROOM.REMOVED:
|
2020-03-06 13:13:24 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
isDeleting: false
|
|
|
|
};
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|