Localstorage woes again; multiple requests; creating common components

This commit is contained in:
James Barnsley
2016-10-18 21:57:29 +13:00
parent bd3ac79055
commit 51bf248ac9
14 changed files with 179 additions and 17 deletions

View File

@ -3,6 +3,13 @@
* Actions and Action Creators
**/
export function setConfig( config ){
return {
type: 'SPOTIFY_SET_CONFIG',
config: config
}
}
export function startAuthorization(){
return {
type: 'SPOTIFY_START_AUTHORIZATION'

View File

@ -33,8 +33,10 @@ const SpotifyMiddleware = (function(){
* The actual middleware inteceptor
**/
return store => next => action => {
switch(action.type) {
var state = store.getState();
switch(action.type){
case 'SPOTIFY_LOAD_ALBUM':
@ -57,21 +59,32 @@ const SpotifyMiddleware = (function(){
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 })
var token = store.getState().spotify.access_token;
sendRequest( token, 'me/following?type=artist' )
sendRequest( state.spotify.access_token, 'me/following?type=artist' )
.then( (response) => {
store.dispatch({ type: 'SPOTIFY_LIBRARY_ARTISTS_LOADED', data: response })
});

View File

@ -35,6 +35,12 @@ export default function reducer(spotify = {}, action){
case 'SPOTIFY_ARTIST_LOADED':
return Object.assign({}, spotify, { artist: action.data });
case 'SPOTIFY_ARTIST_ALBUMS_LOADED':
return Object.assign({}, spotify, { artist_albums: action.data });
case 'SPOTIFY_ARTIST_TRACKS_LOADED':
return Object.assign({}, spotify, { artist_top_tracks: action.data });
case 'SPOTIFY_LIBRARY_ARTISTS_LOADED':
return Object.assign({}, spotify, { libraryArtists: action.data });