Files
Iris/src/js/services/ui/middleware.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-11-11 16:47:32 +13:00
2016-12-14 08:29:24 +13:00
var uiActions = require('./actions.js')
2016-11-11 16:47:32 +13:00
var spotifyActions = require('../spotify/actions.js')
var helpers = require('../../helpers.js')
const UIMiddleware = (function(){
/**
* The actual middleware inteceptor
**/
return store => next => action => {
switch(action.type){
2016-12-13 11:08:13 +13:00
case 'CREATE_NOTIFICATION':
// start a timeout to remove this notification
var timeout = setTimeout(
function(){
2016-12-14 08:29:24 +13:00
store.dispatch(uiActions.removeNotification(action.notification.id))
2016-12-13 11:08:13 +13:00
},
3000
)
// we don't want to stop things happening as usual
next(action)
break
2016-12-14 08:29:24 +13:00
case 'PLAYLIST_TRACKS_ADDED':
store.dispatch(uiActions.createNotification('Added '+action.tracks_uris.length+' tracks to playlist'))
// we don't want to stop things happening as usual
next(action)
break
2016-11-11 16:47:32 +13:00
// This action is irrelevant to us, pass it on to the next middleware
default:
2016-12-13 11:08:13 +13:00
return next(action)
2016-11-11 16:47:32 +13:00
}
}
})();
export default UIMiddleware