2017-11-03 09:06:41 +13:00
|
|
|
|
|
|
|
|
var helpers = require('./../../helpers')
|
|
|
|
|
var lastfmActions = require('./actions')
|
|
|
|
|
var uiActions = require('../ui/actions')
|
|
|
|
|
var pusherActions = require('../pusher/actions')
|
|
|
|
|
|
|
|
|
|
const LastfmMiddleware = (function(){
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The actual middleware inteceptor
|
|
|
|
|
**/
|
|
|
|
|
return store => next => action => {
|
|
|
|
|
var state = store.getState();
|
|
|
|
|
|
|
|
|
|
switch(action.type){
|
|
|
|
|
|
2018-08-17 16:09:36 +12:00
|
|
|
case 'LASTFM_ME_LOADED':
|
|
|
|
|
store.dispatch({
|
|
|
|
|
type: 'LASTFM_USER_LOADED',
|
|
|
|
|
user: action.me
|
|
|
|
|
});
|
|
|
|
|
next(action);
|
|
|
|
|
break;
|
|
|
|
|
|
2017-11-03 09:06:41 +13:00
|
|
|
case 'LASTFM_USER_LOADED':
|
|
|
|
|
var user = Object.assign(
|
|
|
|
|
{},
|
|
|
|
|
action.user,
|
|
|
|
|
{
|
|
|
|
|
uri: "lastfm:user:"+action.user.name
|
|
|
|
|
}
|
|
|
|
|
);
|
2018-08-17 16:09:36 +12:00
|
|
|
store.dispatch(coreActions.userLoaded(user));
|
2017-11-03 09:06:41 +13:00
|
|
|
next(action);
|
|
|
|
|
break;
|
|
|
|
|
|
2017-11-06 16:59:21 +13:00
|
|
|
|
2017-11-03 09:06:41 +13:00
|
|
|
// This action is irrelevant to us, pass it on to the next middleware
|
|
|
|
|
default:
|
|
|
|
|
return next(action);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
export default LastfmMiddleware
|