Refreshing token; Default albums view
This commit is contained in:
@ -22,10 +22,7 @@ const CoreMiddleware = (function(){
|
||||
store.dispatch(mopidyActions.connect())
|
||||
store.dispatch(pusherActions.connect())
|
||||
store.dispatch(lastfmActions.connect())
|
||||
|
||||
if (store.getState().spotify.enabled){
|
||||
store.dispatch(spotifyActions.connect())
|
||||
}
|
||||
store.dispatch(spotifyActions.connect())
|
||||
|
||||
next(action)
|
||||
break
|
||||
|
||||
@ -149,15 +149,24 @@ function refreshToken( dispatch, getState ){
|
||||
})
|
||||
.then(
|
||||
response => {
|
||||
var token = response.spotify_token
|
||||
token.token_expiry = new Date().getTime() + ( token.expires_in * 1000 );
|
||||
token.source = 'mopidy';
|
||||
dispatch({
|
||||
type: 'SPOTIFY_TOKEN_REFRESHED',
|
||||
access_token_provider: 'backend',
|
||||
data: token
|
||||
});
|
||||
resolve(token);
|
||||
if (response.type == 'error'){
|
||||
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
|
||||
dispatch(uiActions.createNotification(response.message,'bad'))
|
||||
console.error('Could not refresh token', response)
|
||||
reject(response)
|
||||
|
||||
} else {
|
||||
var token = response.spotify_token
|
||||
token.token_expiry = new Date().getTime() + ( token.expires_in * 1000 );
|
||||
token.source = 'mopidy';
|
||||
dispatch({
|
||||
type: 'SPOTIFY_TOKEN_REFRESHED',
|
||||
access_token_provider: 'backend',
|
||||
data: token
|
||||
});
|
||||
resolve(token);
|
||||
}
|
||||
|
||||
},
|
||||
error => {
|
||||
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
|
||||
@ -943,7 +952,7 @@ export function playArtistTopTracks(uri){
|
||||
* ======================================================================================
|
||||
**/
|
||||
|
||||
export function getUser( uri ){
|
||||
export function getUser(uri){
|
||||
return (dispatch, getState) => {
|
||||
|
||||
// get the user
|
||||
@ -956,8 +965,15 @@ export function getUser( uri ){
|
||||
});
|
||||
})
|
||||
|
||||
dispatch(getUserPlaylists(uri))
|
||||
}
|
||||
}
|
||||
|
||||
export function getUserPlaylists(user_uri){
|
||||
return (dispatch, getState) => {
|
||||
|
||||
// get the first page of playlists
|
||||
sendRequest( dispatch, getState, 'users/'+ helpers.getFromUri('userid', uri) +'/playlists?limit=40' )
|
||||
sendRequest( dispatch, getState, 'users/'+ helpers.getFromUri('userid', user_uri) +'/playlists?limit=40' )
|
||||
.then( response => {
|
||||
|
||||
var playlists = []
|
||||
@ -979,7 +995,7 @@ export function getUser( uri ){
|
||||
|
||||
dispatch({
|
||||
type: 'SPOTIFY_USER_PLAYLISTS_LOADED',
|
||||
key: uri,
|
||||
key: user_uri,
|
||||
data: response
|
||||
});
|
||||
})
|
||||
|
||||
@ -16,10 +16,6 @@ const SpotifyMiddleware = (function(){
|
||||
|
||||
switch(action.type){
|
||||
|
||||
case 'SPOTIFY_CONNECT':
|
||||
store.dispatch( spotifyActions.getMe() )
|
||||
break
|
||||
|
||||
case 'SPOTIFY_CONNECTED':
|
||||
var label = null
|
||||
if (store.getState().spotify.me) label = store.getState().spotify.me.id
|
||||
@ -31,6 +27,9 @@ const SpotifyMiddleware = (function(){
|
||||
store.dispatch(spotifyActions.getAllLibraryPlaylists())
|
||||
}
|
||||
|
||||
// Get the current logged-in user
|
||||
store.dispatch(spotifyActions.getMe())
|
||||
|
||||
next(action)
|
||||
break
|
||||
|
||||
@ -400,6 +399,13 @@ const SpotifyMiddleware = (function(){
|
||||
store.dispatch(pusherActions.setUsername(name))
|
||||
}
|
||||
ReactGA.event({ category: 'Spotify', action: 'Authorization verified', label: action.data.id })
|
||||
|
||||
store.dispatch({
|
||||
type: 'USER_LOADED',
|
||||
key: action.data.uri,
|
||||
user: action.data
|
||||
})
|
||||
|
||||
next(action)
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user