2022-01-14 22:06:55 +00:00
|
|
|
import { IRoomsAction } from '../actions/rooms';
|
|
|
|
import { ROOMS } from '../actions/actionsTypes';
|
2017-08-17 02:06:22 +00:00
|
|
|
|
2022-01-14 22:06:55 +00:00
|
|
|
export interface IRooms {
|
|
|
|
isFetching: boolean;
|
|
|
|
refreshing: boolean;
|
|
|
|
failure: boolean;
|
|
|
|
errorMessage: Record<string, any>;
|
|
|
|
searchText: string;
|
|
|
|
showServerDropdown: boolean;
|
|
|
|
closeServerDropdown: boolean;
|
|
|
|
showSearchHeader: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const initialState: IRooms = {
|
2019-02-12 16:14:11 +00:00
|
|
|
isFetching: false,
|
2020-02-11 20:13:44 +00:00
|
|
|
refreshing: false,
|
2017-12-08 19:13:21 +00:00
|
|
|
failure: false,
|
2019-02-07 16:13:21 +00:00
|
|
|
errorMessage: {},
|
2018-08-31 16:46:33 +00:00
|
|
|
searchText: '',
|
|
|
|
showServerDropdown: false,
|
|
|
|
closeServerDropdown: false,
|
2018-10-23 21:39:48 +00:00
|
|
|
showSearchHeader: false
|
2017-08-17 02:06:22 +00:00
|
|
|
};
|
|
|
|
|
2022-01-14 22:06:55 +00:00
|
|
|
export default function rooms(state = initialState, action: IRoomsAction): IRooms {
|
2017-08-17 02:06:22 +00:00
|
|
|
switch (action.type) {
|
2022-01-14 22:06:55 +00:00
|
|
|
case ROOMS.REQUEST:
|
2017-11-13 12:58:35 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2019-02-07 16:13:21 +00:00
|
|
|
isFetching: true,
|
|
|
|
failure: false,
|
|
|
|
errorMessage: {}
|
2017-08-17 02:06:22 +00:00
|
|
|
};
|
2022-01-14 22:06:55 +00:00
|
|
|
case ROOMS.SUCCESS:
|
2017-11-13 12:58:35 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2020-02-11 20:13:44 +00:00
|
|
|
isFetching: false,
|
|
|
|
refreshing: false
|
2017-08-17 02:06:22 +00:00
|
|
|
};
|
2022-01-14 22:06:55 +00:00
|
|
|
case ROOMS.FAILURE:
|
2017-11-13 12:58:35 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2017-08-17 02:06:22 +00:00
|
|
|
isFetching: false,
|
2020-02-11 20:13:44 +00:00
|
|
|
refreshing: false,
|
2017-08-17 02:06:22 +00:00
|
|
|
failure: true,
|
|
|
|
errorMessage: action.err
|
|
|
|
};
|
2022-01-14 22:06:55 +00:00
|
|
|
case ROOMS.REFRESH:
|
2020-02-11 20:13:44 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
isFetching: true,
|
|
|
|
refreshing: true
|
|
|
|
};
|
2022-01-14 22:06:55 +00:00
|
|
|
case ROOMS.SET_SEARCH:
|
2017-12-08 19:13:21 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
searchText: action.searchText
|
|
|
|
};
|
2022-01-14 22:06:55 +00:00
|
|
|
case ROOMS.CLOSE_SERVER_DROPDOWN:
|
2018-08-31 16:46:33 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
closeServerDropdown: !state.closeServerDropdown
|
|
|
|
};
|
2022-01-14 22:06:55 +00:00
|
|
|
case ROOMS.TOGGLE_SERVER_DROPDOWN:
|
2018-08-31 16:46:33 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showServerDropdown: !state.showServerDropdown
|
|
|
|
};
|
2022-01-14 22:06:55 +00:00
|
|
|
case ROOMS.OPEN_SEARCH_HEADER:
|
2018-10-23 21:39:48 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showSearchHeader: true
|
|
|
|
};
|
2022-01-14 22:06:55 +00:00
|
|
|
case ROOMS.CLOSE_SEARCH_HEADER:
|
2018-10-23 21:39:48 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showSearchHeader: false
|
|
|
|
};
|
2017-08-17 02:06:22 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|