2017-09-24 19:06:28 -07:00
|
|
|
import {
|
|
|
|
CloseNotificationAction,
|
2017-07-02 00:49:06 -05:00
|
|
|
Notification,
|
2017-09-24 19:06:28 -07:00
|
|
|
NotificationsAction,
|
|
|
|
ShowNotificationAction
|
2017-06-23 01:16:21 +04:00
|
|
|
} from 'actions/notifications';
|
2017-09-24 19:06:28 -07:00
|
|
|
import { TypeKeys } from 'actions/notifications/constants';
|
2017-06-27 02:27:55 +04:00
|
|
|
export type State = Notification[];
|
2017-06-22 03:31:59 +04:00
|
|
|
|
2017-07-27 13:05:09 -04:00
|
|
|
export const INITIAL_STATE: State = [];
|
2017-06-22 03:31:59 +04:00
|
|
|
|
2017-06-23 01:16:21 +04:00
|
|
|
function showNotification(state: State, action: ShowNotificationAction): State {
|
2017-07-02 00:49:06 -05:00
|
|
|
return state.concat(action.payload);
|
2017-06-23 01:16:21 +04:00
|
|
|
}
|
|
|
|
|
2017-12-19 17:46:34 -05:00
|
|
|
function closeNotification(state: State, action: CloseNotificationAction): State {
|
2017-07-02 00:49:06 -05:00
|
|
|
state = [...state];
|
|
|
|
state.splice(state.indexOf(action.payload), 1);
|
|
|
|
return state;
|
2017-06-23 01:16:21 +04:00
|
|
|
}
|
|
|
|
|
2017-12-18 18:29:26 -05:00
|
|
|
export function notifications(state: State = INITIAL_STATE, action: NotificationsAction): State {
|
2017-07-02 00:49:06 -05:00
|
|
|
switch (action.type) {
|
2017-09-24 19:06:28 -07:00
|
|
|
case TypeKeys.SHOW_NOTIFICATION:
|
2017-07-02 00:49:06 -05:00
|
|
|
return showNotification(state, action);
|
2017-09-24 19:06:28 -07:00
|
|
|
case TypeKeys.CLOSE_NOTIFICATION:
|
2017-07-02 00:49:06 -05:00
|
|
|
return closeNotification(state, action);
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2017-06-22 03:31:59 +04:00
|
|
|
}
|