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

38 lines
984 B
JavaScript
Raw Normal View History

import { formatUser } from '../../util/format';
2019-09-05 15:36:11 +12:00
const coreActions = require('../core/actions');
const lastfmActions = require('./actions');
const LastfmMiddleware = (function () {
2019-09-05 15:36:11 +12:00
return (store) => (next) => (action) => {
switch (action.type) {
2019-09-05 15:36:11 +12:00
case 'LASTFM_ME_LOADED':
var me = formatUser(action.me);
2019-09-05 15:36:11 +12:00
Object.assign(
me,
{
uri: `lastfm:user:${me.name}`,
},
);
store.dispatch(coreActions.userLoaded(me));
action.me = me;
next(action);
break;
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;
default:
return next(action);
}
2019-09-05 15:36:11 +12:00
};
}());
export default LastfmMiddleware;