verdnatura-chat/app/reducers/rooms.ts

84 lines
1.6 KiB
TypeScript
Raw Normal View History

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