2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
17 import {actionTypes} from './UserNotificationsConstants.js';
19 export default (state = {}, action) => {
20 switch (action.type) {
21 case actionTypes.NOTIFICATION:
22 let list = (state.notificationsList) ? state.notificationsList : [];
23 const {notifications, lastScanned} = action.data;
27 notificationsList: [...notifications, ...list],
28 numOfNotSeenNotifications: state.numOfNotSeenNotifications + notifications.length
30 case actionTypes.LOAD_NOTIFICATIONS:
34 notificationsList: action.result.notifications,
35 notifications: undefined
37 case actionTypes.LOAD_PREV_NOTIFICATIONS:
38 const {notifications: prevNotifications, endOfPage: newEndOfPage} = action.result;
42 ...state.notificationsList,
45 endOfPage: newEndOfPage
47 case actionTypes.UPDATE_READ_NOTIFICATION:
48 let {notificationForUpdate} = action;
49 notificationForUpdate = {...notificationForUpdate, read: true};
50 const indexForEdit = state.notificationsList.findIndex(notification => notification.eventId === notificationForUpdate.eventId);
54 ...state.notificationsList.slice(0, indexForEdit),
55 notificationForUpdate,
56 ...state.notificationsList.slice(indexForEdit + 1)
59 case actionTypes.RESET_NEW_NOTIFICATIONS:
62 numOfNotSeenNotifications: 0
64 case actionTypes.TOGGLE_OVERLAY:
67 showNotificationsOverlay: action.showNotificationsOverlay