verdnatura-chat/app/reducers/rooms.ts

84 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-02-28 18:00:47 +00:00
import { IRoomsAction } from '../actions/rooms';
import { ROOMS } from '../actions/actionsTypes';
2017-08-17 02:06:22 +00:00
2022-02-28 18:00:47 +00:00
export interface IRooms {
isFetching: boolean;
refreshing: boolean;
failure: boolean;
errorMessage: Record<string, any> | string;
searchText: string;
showServerDropdown: boolean;
closeServerDropdown: boolean;
showSearchHeader: boolean;
}
export const initialState: IRooms = {
isFetching: false,
2020-02-19 19:43:47 +00:00
refreshing: false,
failure: false,
errorMessage: {},
searchText: '',
showServerDropdown: false,
closeServerDropdown: false,
showSearchHeader: false
2017-08-17 02:06:22 +00:00
};
2022-02-28 18:00:47 +00:00
export default function rooms(state = initialState, action: IRoomsAction): IRooms {
2017-08-17 02:06:22 +00:00
switch (action.type) {
2022-02-28 18:00:47 +00:00
case ROOMS.REQUEST:
2017-11-13 12:58:35 +00:00
return {
...state,
isFetching: true,
failure: false,
errorMessage: {}
2017-08-17 02:06:22 +00:00
};
2022-02-28 18:00:47 +00:00
case ROOMS.SUCCESS:
2017-11-13 12:58:35 +00:00
return {
...state,
2020-02-19 19:43:47 +00:00
isFetching: false,
refreshing: false
2017-08-17 02:06:22 +00:00
};
2022-02-28 18:00:47 +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-19 19:43:47 +00:00
refreshing: false,
2017-08-17 02:06:22 +00:00
failure: true,
errorMessage: action.err
};
2022-02-28 18:00:47 +00:00
case ROOMS.REFRESH:
2020-02-19 19:43:47 +00:00
return {
...state,
isFetching: true,
refreshing: true
};
2022-02-28 18:00:47 +00:00
case ROOMS.SET_SEARCH:
return {
...state,
searchText: action.searchText
};
2022-02-28 18:00:47 +00:00
case ROOMS.CLOSE_SERVER_DROPDOWN:
return {
...state,
closeServerDropdown: !state.closeServerDropdown
};
2022-02-28 18:00:47 +00:00
case ROOMS.TOGGLE_SERVER_DROPDOWN:
return {
...state,
showServerDropdown: !state.showServerDropdown
};
2022-02-28 18:00:47 +00:00
case ROOMS.OPEN_SEARCH_HEADER:
return {
...state,
showSearchHeader: true
};
2022-02-28 18:00:47 +00:00
case ROOMS.CLOSE_SEARCH_HEADER:
return {
...state,
showSearchHeader: false
};
2017-08-17 02:06:22 +00:00
default:
return state;
}
}