Simplified localstorage handler; Duration formatter

This commit is contained in:
James Barnsley
2016-10-18 16:53:33 +13:00
parent 82b13707f9
commit bd3ac79055
9 changed files with 70 additions and 19 deletions

View File

@ -42,7 +42,13 @@ const SpotifyMiddleware = (function(){
var id = action.uri.replace('spotify:album:','');
sendRequest( false, 'albums/'+id )
.then( (response) => {
.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;
@ -63,7 +69,7 @@ const SpotifyMiddleware = (function(){
case 'SPOTIFY_LOAD_LIBRARY_ARTISTS':
store.dispatch({ type: 'SPOTIFY_LIBRARY_ARTISTS_LOADED', data: false })
var token = store.getState().spotify.token;
var token = store.getState().spotify.access_token;
sendRequest( token, 'me/following?type=artist' )
.then( (response) => {
@ -80,11 +86,6 @@ const SpotifyMiddleware = (function(){
console.log('Spotify wants to DISconnect')
break;
case 'SPOTIFY_COMPLETE_AUTHORIZATION':
next(action);
localStorage.setItem('spotify', JSON.stringify({ access_token: action.data.access_token, refresh_token: action.data.refresh_token }));
break;
// This action is irrelevant to us, pass it on to the next middleware
default:
return next(action);

View File

@ -9,10 +9,19 @@ export default function reducer(spotify = {}, action){
return Object.assign({}, spotify, { authorizing: true });
case 'SPOTIFY_COMPLETE_AUTHORIZATION':
return Object.assign({}, spotify, { authorizing: false, authorization: action.data, token: action.data.access_token });
return Object.assign({}, spotify, {
authorizing: false,
authorized: true,
authorization: action.data,
token: action.data.access_token
});
case 'SPOTIFY_REMOVE_AUTHORIZATION':
return Object.assign({}, spotify, { authorizing: false, authorization: false });
return Object.assign({}, spotify, {
authorizing: false,
authorization: false,
authorized: false
});
case 'SPOTIFY_CONNECTED':
return Object.assign({}, spotify, { connected: true, connecting: false });