Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Listen to WS notification to update inbox #1157
Browse files Browse the repository at this point in the history
  • Loading branch information
wiadev committed Sep 1, 2017
1 parent 730981c commit 62d9fec
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
14 changes: 13 additions & 1 deletion src/actions/AppActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ export function loginSuccess(auth) {
dispatch(updateNotification(
notification.notification, notification.unreadCount
));
}else if(notification.eventType === 'Delete') {
dispatch(removeNotification(
notification.notificationId, notification.unreadCount
));
}else if(notification.eventType === 'New'){
dispatch(newNotification(
notification.notification, notification.unreadCount
Expand Down Expand Up @@ -326,7 +330,7 @@ export function setNotificationProgress(key, progress){
}
}

export function deleteNotification(key){
export function deleteNotification(key) {
return {
type: types.DELETE_NOTIFICATION,
key: key
Expand Down Expand Up @@ -381,6 +385,14 @@ export function newNotification(msg, count) {
}
}

export function removeNotification(msg, count) {
return {
type: types.REMOVE_NOTIFICATION,
notification: msg,
unreadCount: count
}
}

export function setProcessPending() {
return {
type: types.SET_PROCESS_STATE_PENDING
Expand Down
9 changes: 1 addition & 8 deletions src/components/inbox/Inbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,7 @@ class Inbox extends Component {
e.preventDefault();
e.stopPropagation();

deleteUserNotification(item.id).then( () => {
getNotifications().then(response => {
dispatch(getNotificationsSuccess(
response.data.notifications,
response.data.unreadCount
));
});
});
deleteUserNotification(item.id).then( () => {});
}

componentDidUpdate() {
Expand Down
1 change: 1 addition & 0 deletions src/constants/ActionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const SELECT_TABLE_ITEMS = 'SELECT_TABLE_ITEMS';

export const GET_NOTIFICATIONS_SUCCESS = 'GET_NOTIFICATIONS_SUCCESS';
export const NEW_NOTIFICATION = 'NEW_NOTIFICATION';
export const REMOVE_NOTIFICATION = 'REMOVE_NOTIFICATION';
export const UPDATE_NOTIFICATION = 'UPDATE_NOTIFICATION';

export const OPEN_RAW_MODAL = 'OPEN_RAW_MODAL';
Expand Down
10 changes: 10 additions & 0 deletions src/reducers/appHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ export default function appHandler(state = initialState, action) {
unreadCount: {$set: action.unreadCount}
}
})
case types.REMOVE_NOTIFICATION:
return update(state, {
inbox: {
notifications: { $set:
state.inbox.notifications.filter(item =>
item.id !== action.notification
)},
unreadCount: {$set: action.unreadCount}
}
})
case types.UPDATE_NOTIFICATION:
return update(state, {
inbox: {
Expand Down

0 comments on commit 62d9fec

Please sign in to comment.