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