Loading album via actions + middleware
This commit is contained in:
@ -4,9 +4,25 @@ import actions from './actions'
|
||||
const SpotifyMiddleware = (function(){
|
||||
|
||||
return store => next => action => {
|
||||
|
||||
|
||||
switch(action.type) {
|
||||
|
||||
case 'SPOTIFY_LOAD_ALBUM':
|
||||
|
||||
// clear the current album
|
||||
store.dispatch({ type: 'SPOTIFY_ALBUM_LOADED', data: false })
|
||||
|
||||
var id = action.uri.replace('spotify:album:','');
|
||||
$.ajax({
|
||||
method: 'GET',
|
||||
cache: true,
|
||||
url: 'https://api.spotify.com/v1/albums/'+id,
|
||||
success: function(album){
|
||||
store.dispatch({ type: 'SPOTIFY_ALBUM_LOADED', data: album })
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_CONNECT':
|
||||
|
||||
console.log('Spotify wants to connect')
|
||||
|
||||
@ -14,6 +14,9 @@ export default function reducer(spotify = {}, action){
|
||||
case 'SPOTIFY_DISCONNECTED':
|
||||
return Object.assign({}, spotify, { connected: false, connecting: false });
|
||||
|
||||
case 'SPOTIFY_ALBUM_LOADED':
|
||||
return Object.assign({}, spotify, { album: action.data });
|
||||
|
||||
default:
|
||||
return spotify
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user