Sorting part 2 - should be at storage level perhaps; Thumbnail not updating fixed
This commit is contained in:
@ -52,7 +52,7 @@ function getToken( dispatch, getState ){
|
||||
|
||||
// token is okay for now, so just resolve with the current token
|
||||
if( new Date().getTime() < getState().spotify.token_expiry ){
|
||||
resolve(getState().spotify.access_token);
|
||||
resolve(getState().spotify.access_token)
|
||||
return
|
||||
}
|
||||
|
||||
@ -81,16 +81,17 @@ function refreshToken( dispatch, getState ){
|
||||
})
|
||||
.then(
|
||||
response => {
|
||||
response.token_expiry = new Date().getTime() + ( response.expires_in * 1000 );
|
||||
response.source = 'spotify';
|
||||
response.token_expiry = new Date().getTime() + ( response.expires_in * 1000 )
|
||||
response.source = 'spotify'
|
||||
dispatch({
|
||||
type: 'SPOTIFY_TOKEN_REFRESHED',
|
||||
provider: 'spotify-http-api',
|
||||
data: response
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
resolve(response)
|
||||
},
|
||||
error => {
|
||||
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
|
||||
console.error('Could not refresh token', error)
|
||||
reject(error)
|
||||
}
|
||||
@ -116,6 +117,7 @@ function refreshToken( dispatch, getState ){
|
||||
resolve(response);
|
||||
},
|
||||
error => {
|
||||
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
|
||||
console.error('Could not refresh token', error)
|
||||
reject(error)
|
||||
}
|
||||
|
||||
@ -4,10 +4,13 @@ export default function reducer(spotify = {}, action){
|
||||
|
||||
case 'SPOTIFY_CONNECT':
|
||||
case 'SPOTIFY_CONNECTING':
|
||||
return Object.assign({}, spotify, { connected: false, connecting: true });
|
||||
return Object.assign({}, spotify, { connected: false, connecting: true })
|
||||
|
||||
case 'SPOTIFY_CONNECTED':
|
||||
return Object.assign({}, spotify, { connected: true, connecting: false });
|
||||
return Object.assign({}, spotify, { connected: true, connecting: false })
|
||||
|
||||
case 'SPOTIFY_DISCONNECTED':
|
||||
return Object.assign({}, spotify, { connected: false, connecting: false })
|
||||
|
||||
case 'PUSHER_SPOTIFY_TOKEN':
|
||||
if( spotify.authorized ) return spotify;
|
||||
@ -17,7 +20,7 @@ export default function reducer(spotify = {}, action){
|
||||
authorization: false,
|
||||
access_token: action.data.access_token,
|
||||
token_expiry: action.data.token_expiry
|
||||
});
|
||||
})
|
||||
|
||||
case 'SPOTIFY_AUTHORIZATION_GRANTED':
|
||||
return Object.assign({}, spotify, {
|
||||
@ -27,7 +30,7 @@ export default function reducer(spotify = {}, action){
|
||||
access_token: action.data.access_token,
|
||||
refresh_token: action.data.refresh_token,
|
||||
token_expiry: action.data.token_expiry
|
||||
});
|
||||
})
|
||||
|
||||
case 'SPOTIFY_AUTHORIZATION_REVOKED':
|
||||
return Object.assign({}, spotify, {
|
||||
@ -38,45 +41,46 @@ export default function reducer(spotify = {}, action){
|
||||
refresh_token: false,
|
||||
token_expiry: 0,
|
||||
me: false
|
||||
});
|
||||
})
|
||||
|
||||
case 'SPOTIFY_TOKEN_REFRESHING':
|
||||
return Object.assign({}, spotify, { refreshing_token: true });
|
||||
return Object.assign({}, spotify, { refreshing_token: true })
|
||||
|
||||
case 'SPOTIFY_TOKEN_REFRESHED':
|
||||
return Object.assign({}, spotify, {
|
||||
connected: true,
|
||||
refreshing_token: false,
|
||||
authorization: action.data,
|
||||
access_token: action.data.access_token,
|
||||
token_expiry: action.data.token_expiry,
|
||||
provider: action.provider
|
||||
});
|
||||
})
|
||||
|
||||
case 'SPOTIFY_DISCONNECTED':
|
||||
return Object.assign({}, spotify, { connected: false, connecting: false });
|
||||
return Object.assign({}, spotify, { connected: false, connecting: false })
|
||||
|
||||
case 'SPOTIFY_ME_LOADED':
|
||||
return Object.assign({}, spotify, { me: action.data });
|
||||
return Object.assign({}, spotify, { me: action.data })
|
||||
|
||||
case 'SPOTIFY_ARTISTS_LOADED':
|
||||
if( !action.data ) return Object.assign({}, spotify)
|
||||
return Object.assign({}, spotify, {
|
||||
artists: action.data.artists.items,
|
||||
artists_more: action.data.artists.next
|
||||
});
|
||||
})
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ARTISTS_LOADED':
|
||||
if( !action.data ) return Object.assign({}, spotify)
|
||||
return Object.assign({}, spotify, {
|
||||
library_artists: action.data.artists.items,
|
||||
library_artists_more: action.data.artists.next
|
||||
});
|
||||
})
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ARTISTS_LOADED_MORE':
|
||||
return Object.assign({}, spotify, {
|
||||
library_artists: [ ...spotify.library_artists, ...action.data.artists.items ],
|
||||
library_artists_more: action.data.artists.next
|
||||
});
|
||||
})
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ALBUMS_LOADED':
|
||||
if( !action.data ) return Object.assign({}, spotify)
|
||||
@ -93,7 +97,7 @@ export default function reducer(spotify = {}, action){
|
||||
return Object.assign({}, spotify, {
|
||||
library_albums: albums,
|
||||
library_albums_more: action.data.next
|
||||
});
|
||||
})
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ALBUMS_LOADED_MORE':
|
||||
var albums = []
|
||||
@ -109,7 +113,7 @@ export default function reducer(spotify = {}, action){
|
||||
return Object.assign({}, spotify, {
|
||||
library_albums: [...spotify.library_albums, ...albums ],
|
||||
library_albums_more: action.data.next
|
||||
});
|
||||
})
|
||||
|
||||
case 'SPOTIFY_LIBRARY_TRACKS_LOADED':
|
||||
if( !action.data ) return Object.assign({}, spotify)
|
||||
@ -126,7 +130,7 @@ export default function reducer(spotify = {}, action){
|
||||
return Object.assign({}, spotify, {
|
||||
library_tracks: tracks,
|
||||
library_tracks_more: action.data.next
|
||||
});
|
||||
})
|
||||
|
||||
case 'SPOTIFY_LIBRARY_TRACKS_LOADED_MORE':
|
||||
var tracks = Object.assign([], action.data.items)
|
||||
@ -142,19 +146,19 @@ export default function reducer(spotify = {}, action){
|
||||
return Object.assign({}, spotify, {
|
||||
library_tracks: [...spotify.library_tracks, ...tracks],
|
||||
library_tracks_more: action.data.next
|
||||
});
|
||||
})
|
||||
|
||||
case 'SPOTIFY_FEATURED_PLAYLISTS_LOADED':
|
||||
return Object.assign({}, spotify, { featured_playlists: action.data });
|
||||
return Object.assign({}, spotify, { featured_playlists: action.data })
|
||||
|
||||
case 'SPOTIFY_CATEGORIES_LOADED':
|
||||
return Object.assign({}, spotify, { categories: action.data });
|
||||
return Object.assign({}, spotify, { categories: action.data })
|
||||
|
||||
case 'SPOTIFY_CATEGORY_LOADED':
|
||||
return Object.assign({}, spotify, { category: action.data });
|
||||
return Object.assign({}, spotify, { category: action.data })
|
||||
|
||||
case 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED':
|
||||
return Object.assign({}, spotify, { category_playlists: action.data });
|
||||
return Object.assign({}, spotify, { category_playlists: action.data })
|
||||
|
||||
case 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED_MORE':
|
||||
return Object.assign({}, spotify, { category_playlists: {
|
||||
@ -162,7 +166,7 @@ export default function reducer(spotify = {}, action){
|
||||
next: action.data.next,
|
||||
previous: action.data.previous,
|
||||
items: [ ...spotify.category_playlists.items, ...action.data.items ]
|
||||
}});
|
||||
}})
|
||||
|
||||
case 'SPOTIFY_NEW_RELEASES_LOADED':
|
||||
return Object.assign({}, spotify, { new_releases: action.data });
|
||||
@ -173,7 +177,7 @@ export default function reducer(spotify = {}, action){
|
||||
next: action.data.albums.next,
|
||||
previous: action.data.albums.previous,
|
||||
items: [ ...spotify.new_releases.items, ...action.data.albums.items ]
|
||||
}});
|
||||
}})
|
||||
|
||||
default:
|
||||
return spotify
|
||||
|
||||
Reference in New Issue
Block a user