2017-11-03 09:06:41 +13:00
|
|
|
|
2018-08-22 08:13:08 +12:00
|
|
|
var helpers = require('./../../helpers');
|
|
|
|
|
var coreActions = require('../core/actions');
|
2018-09-30 20:09:12 +13:00
|
|
|
var lastfmActions = require('./actions');
|
2017-11-03 09:06:41 +13:00
|
|
|
|
|
|
|
|
const LastfmMiddleware = (function(){
|
|
|
|
|
|
|
|
|
|
return store => next => action => {
|
|
|
|
|
switch(action.type){
|
|
|
|
|
|
2018-08-17 16:09:36 +12:00
|
|
|
case 'LASTFM_ME_LOADED':
|
2018-09-12 21:42:55 +12:00
|
|
|
var me = helpers.formatUser(action.me);
|
|
|
|
|
Object.assign(
|
|
|
|
|
me,
|
2017-11-03 09:06:41 +13:00
|
|
|
{
|
2018-09-12 21:42:55 +12:00
|
|
|
uri: "lastfm:user:"+me.name
|
2017-11-03 09:06:41 +13:00
|
|
|
}
|
|
|
|
|
);
|
2018-09-12 21:42:55 +12:00
|
|
|
store.dispatch(coreActions.userLoaded(me));
|
|
|
|
|
action.me = me;
|
|
|
|
|
next(action);
|
2017-11-03 09:06:41 +13:00
|
|
|
break;
|
|
|
|
|
|
2018-09-30 20:09:12 +13:00
|
|
|
case 'LASTFM_IMPORT_AUTHORIZATION':
|
|
|
|
|
|
|
|
|
|
// Wait a few moments before we fetch, allowing the import to complete first
|
|
|
|
|
// TODO: Use callbacks for better code accuracy
|
|
|
|
|
setTimeout(() => {store.dispatch(lastfmActions.getMe())}, 100);
|
|
|
|
|
|
|
|
|
|
next(action);
|
|
|
|
|
break;
|
|
|
|
|
|
2017-11-03 09:06:41 +13:00
|
|
|
default:
|
|
|
|
|
return next(action);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
export default LastfmMiddleware
|