Notifications as object for better targetting; Notifications closing vs removing for animation window

This commit is contained in:
James Barnsley
2018-02-28 08:44:38 +13:00
parent 7fa1fcf9e7
commit 2a95af89de
7 changed files with 62 additions and 54 deletions

View File

@ -70,40 +70,41 @@ const UIMiddleware = (function(){
case 'CREATE_NOTIFICATION':
// start a timeout to remove this notification
// start a timeout to close this notification
if (!action.notification.sticky){
var timeout = setTimeout(
function(){
store.dispatch(uiActions.removeNotification(action.notification.key))
store.dispatch(uiActions.closeNotification(action.notification.key))
},
action.notification.duration * 1000
)
}
next(action)
break
next(action);
break;
case 'REMOVE_NOTIFICATION':
var notifications = Object.assign([], store.getState().ui.notifications)
function getByKey(notification){
return notification.key === action.key
}
var index = notifications.findIndex(getByKey)
// Save our index for the reducer to use. Saves us from re-finding by key
action.index = index
case 'CLOSE_NOTIFICATION':
var notifications = Object.assign({}, store.getState().ui.notifications);
// If a broadcast, add to suppressed_broadcasts
if (index > -1 && typeof(notifications[index]) !== 'undefined' && notifications[index].type == 'broadcast'){
if (notifications[action.key] && notifications[action.key].type == 'broadcast'){
store.dispatch({
type: 'SUPPRESS_BROADCAST',
key: notifications[index].key
key: action.key
})
}
next(action)
break
// start a timeout to remove this notification
// This gives us time to animate out the notification before we remove the data
var timeout = setTimeout(
function(){
store.dispatch(uiActions.removeNotification(action.key))
},
200
)
next(action);
break;
case 'BROADCASTS_LOADED':
var suppressed_broadcasts = []