Fiddling with thunk; More library endpoints

This commit is contained in:
James Barnsley
2016-10-20 21:38:01 +13:00
parent d659eec7ab
commit daab2133df
16 changed files with 413 additions and 163 deletions

View File

@ -47,67 +47,6 @@ const SpotifyMiddleware = (function(){
});
break;
case 'SPOTIFY_LOAD_ALBUM':
store.dispatch({ type: 'SPOTIFY_ALBUM_LOADED', data: false })
var id = action.uri.replace('spotify:album:','');
sendRequest( false, 'albums/'+id )
.then( (response) => {
for( var i = 0; i < response.tracks.items.length; i++ ){
response.tracks.items[i].album = {
name: response.name,
uri: response.uri
}
}
store.dispatch({ type: 'SPOTIFY_ALBUM_LOADED', data: response })
});
break;
case 'SPOTIFY_LOAD_ARTIST':
store.dispatch({ type: 'SPOTIFY_ARTIST_LOADED', data: false })
store.dispatch({ type: 'SPOTIFY_ARTIST_ALBUMS_LOADED', data: false })
var id = action.uri.replace('spotify:artist:','');
sendRequest( false, 'artists/'+id )
.then( (response) => {
store.dispatch({ type: 'SPOTIFY_ARTIST_LOADED', data: response })
});
sendRequest( false, 'artists/'+id+'/albums' )
.then( (response) => {
store.dispatch({ type: 'SPOTIFY_ARTIST_ALBUMS_LOADED', data: response })
});
sendRequest( false, 'artists/'+id+'/top-tracks?country='+state.spotify.country )
.then( (response) => {
store.dispatch({ type: 'SPOTIFY_ARTIST_TRACKS_LOADED', data: response })
});
break;
case 'SPOTIFY_LOAD_LIBRARY_ARTISTS':
store.dispatch({ type: 'SPOTIFY_LIBRARY_ARTISTS_LOADED', data: false })
sendRequest( state.spotify.access_token, 'me/following?type=artist' )
.then( (response) => {
store.dispatch({ type: 'SPOTIFY_LIBRARY_ARTISTS_LOADED', data: response })
});
break;
case 'SPOTIFY_CONNECT':
console.log('Spotify wants to connect')
break;
case 'SPOTIFY_DISCONNECT':
console.log('Spotify wants to DISconnect')
break;
// This action is irrelevant to us, pass it on to the next middleware
default:
return next(action);