Processor cancelled vs finished; Re-run processor if incomplete during next render

This commit is contained in:
James Barnsley
2017-08-15 16:36:50 +12:00
parent 6f0088204b
commit f51e83099e
14 changed files with 156 additions and 106 deletions

View File

@ -597,10 +597,10 @@ export function following(uri, method = 'GET'){
if( typeof(is_following) === 'object' ) is_following = is_following[0]
dispatch({
type: asset_name.toUpperCase()+'_LIBRARY_CHECK',
type: 'SPOTIFY_LIBRARY_'+asset_name.toUpperCase()+'_CHECK',
key: uri,
in_library: is_following
});
})
});
}
}
@ -1298,6 +1298,7 @@ export function reorderPlaylistTracks( uri, range_start, range_length, insert_be
export function getLibraryPlaylists(){
return (dispatch, getState) => {
dispatch({type: 'SPOTIFY_LIBRARY_PLAYLISTS_CLEAR'})
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR','Loading Spotify playlists', {next: 'me/playlists?limit=50'}))
}
}
@ -1317,7 +1318,7 @@ export function getLibraryPlaylistsProcessor(data){
var processor = getState().ui.processes['SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR']
if (processor.cancelling){
dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR'))
dispatch(uiActions.processCancelled('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR'))
return false
}
}
@ -1343,6 +1344,7 @@ export function getLibraryPlaylistsProcessor(data){
export function getLibraryArtists(){
return (dispatch, getState) => {
dispatch({type: 'SPOTIFY_LIBRARY_ARTISTS_CLEAR'})
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR','Loading Spotify artists', {next: 'me/following?type=artist&limit=50'}))
}
}
@ -1362,7 +1364,7 @@ export function getLibraryArtistsProcessor(data){
var processor = getState().ui.processes['SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR']
if (processor.cancelling){
dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR'))
dispatch(uiActions.processCancelled('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR'))
return false
}
}
@ -1388,6 +1390,7 @@ export function getLibraryArtistsProcessor(data){
export function getLibraryAlbums(){
return (dispatch, getState) => {
dispatch({type: 'SPOTIFY_LIBRARY_ALBUMS_CLEAR'})
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR','Loading Spotify albums', {next: 'me/albums?limit=50'}))
}
}
@ -1407,7 +1410,7 @@ export function getLibraryAlbumsProcessor(data){
var processor = getState().ui.processes['SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR']
if (processor.cancelling){
dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR'))
dispatch(uiActions.processCancelled('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR'))
return false
}
}

View File

@ -174,6 +174,66 @@ export default function reducer(spotify = {}, action){
}
return Object.assign({}, spotify, { library_albums: uris })
case 'SPOTIFY_LIBRARY_PLAYLISTS_CLEAR':
return Object.assign({}, spotify, { library_playlists: [] })
case 'SPOTIFY_LIBRARY_ARTISTS_CLEAR':
return Object.assign({}, spotify, { library_artists: [] })
case 'SPOTIFY_LIBRARY_ALBUMS_CLEAR':
return Object.assign({}, spotify, { library_albums: [] })
case 'SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR_CANCELLED':
return Object.assign({}, spotify, { library_playlists_status: 'cancelled' })
case 'SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR_FINISHED':
return Object.assign({}, spotify, { library_playlists_status: 'finished' })
case 'SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR_CANCELLED':
return Object.assign({}, spotify, { library_artists_status: 'cancelled' })
case 'SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR_FINISHED':
return Object.assign({}, spotify, { library_artists_status: 'finished' })
case 'SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR_CANCELLED':
return Object.assign({}, spotify, { library_albums_status: 'cancelled' })
case 'SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR_FINISHED':
return Object.assign({}, spotify, { library_albums_status: 'finished' })
case 'SPOTIFY_LIBRARY_ALBUM_CHECK':
var items = Object.assign([], spotify.library_albums)
var index = items.indexOf(action.key)
if (index > -1 && !action.in_library){
items.splice(index, 1)
} else if (index < 0 && action.in_library){
items.push(action.key)
}
return Object.assign({}, spotify, { library_albums: items });
case 'SPOTIFY_LIBRARY_ARTIST_CHECK':
var items = Object.assign([], spotify.library_artists)
var index = items.indexOf(action.key)
if (index > -1 && !action.in_library){
items.splice(index, 1)
} else if (index < 0 && action.in_library){
items.push(action.key)
}
return Object.assign({}, spotify, { library_artists: items });
case 'SPOTIFY_LIBRARY_PLAYLIST_CHECK':
var items = Object.assign([], spotify.library_playlists)
var index = items.indexOf(action.key)
if (index > -1 && !action.in_library){
items.splice(index, 1)
} else if (index < 0 && action.in_library){
items.push(action.key)
}
return Object.assign({}, spotify, { library_playlists: items });
default:
return spotify
}