Multiple notifications are back; Customisable notification.id for rolling updates

This commit is contained in:
James Barnsley
2017-04-05 09:01:20 +12:00
parent 9d56a05fc4
commit 6bae5c348c
8 changed files with 63 additions and 37 deletions

View File

@ -224,14 +224,13 @@ export function createBrowserNotification( data ){
}
}
export function createNotification(content, type = 'default', is_shortcut = false){
export function createNotification(content, type = 'default', id = helpers.generateGuid()){
return {
type: 'CREATE_NOTIFICATION',
notification: {
id: helpers.generateGuid(),
id: id,
type: type,
content: content,
is_shortcut: is_shortcut
content: content
}
}
}

View File

@ -268,13 +268,15 @@ const UIMiddleware = (function(){
case 'CREATE_NOTIFICATION':
// start a timeout to remove this notification
var timeout = setTimeout(
function(){
store.dispatch(uiActions.removeNotification(action.notification.id))
},
3000
)
// start a timeout to remove this (non loading) notification
if (action.notification.type != 'loading'){
var timeout = setTimeout(
function(){
store.dispatch(uiActions.removeNotification(action.notification.id))
},
(action.notification.type == 'shortcut' ? 1000 : 3000)
)
}
next(action)
break

View File

@ -711,6 +711,7 @@ export default function reducer(ui = {}, action){
case 'CREATE_NOTIFICATION':
var notifications = [...ui.notifications, action.notification]
notifications = helpers.mergeDuplicates(notifications,'id')
return Object.assign({}, ui, { notifications: notifications })
case 'REMOVE_NOTIFICATION':