Resume-able processes for loading library
This commit is contained in:
@ -1298,8 +1298,15 @@ 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'}))
|
||||
var last_run = getState().ui.processes.SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR
|
||||
|
||||
if (!last_run){
|
||||
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR','Loading Spotify playlists', {next: 'me/playlists?limit=50'}))
|
||||
} else if (last_run.status == 'cancelled'){
|
||||
dispatch(uiActions.resumeProcess('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR'))
|
||||
} else if (last_run.status == 'finished'){
|
||||
// TODO: do we want to force a refresh?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1317,7 +1324,7 @@ export function getLibraryPlaylistsProcessor(data){
|
||||
if (getState().ui.processes['SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR'] !== undefined){
|
||||
var processor = getState().ui.processes['SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR']
|
||||
|
||||
if (processor.cancelling){
|
||||
if (processor.status == 'cancelling'){
|
||||
dispatch(uiActions.processCancelled('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR'))
|
||||
return false
|
||||
}
|
||||
@ -1328,7 +1335,7 @@ export function getLibraryPlaylistsProcessor(data){
|
||||
var total = response.total
|
||||
var loaded = getState().spotify.library_playlists.length
|
||||
var remaining = total - loaded
|
||||
dispatch(uiActions.updateProcess('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR', 'Loading '+remaining+' Spotify playlists'))
|
||||
dispatch(uiActions.updateProcess('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR', 'Loading '+remaining+' Spotify playlists', {next: response.next}))
|
||||
dispatch(uiActions.runProcess('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR', {next: response.next}))
|
||||
} else {
|
||||
dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR'))
|
||||
@ -1344,8 +1351,15 @@ 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'}))
|
||||
var last_run = getState().ui.processes.SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR
|
||||
|
||||
if (!last_run){
|
||||
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR','Loading Spotify artists', {next: 'me/following?type=artist&limit=50'}))
|
||||
} else if (last_run.status == 'cancelled'){
|
||||
dispatch(uiActions.resumeProcess('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR'))
|
||||
} else if (last_run.status == 'finished'){
|
||||
// TODO: do we want to force a refresh?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1363,7 +1377,7 @@ export function getLibraryArtistsProcessor(data){
|
||||
if (getState().ui.processes['SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR'] !== undefined){
|
||||
var processor = getState().ui.processes['SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR']
|
||||
|
||||
if (processor.cancelling){
|
||||
if (processor.status == 'cancelling'){
|
||||
dispatch(uiActions.processCancelled('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR'))
|
||||
return false
|
||||
}
|
||||
@ -1374,7 +1388,7 @@ export function getLibraryArtistsProcessor(data){
|
||||
var total = response.artists.total
|
||||
var loaded = getState().spotify.library_artists.length
|
||||
var remaining = total - loaded
|
||||
dispatch(uiActions.updateProcess('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR', 'Loading '+remaining+' Spotify artists'))
|
||||
dispatch(uiActions.updateProcess('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR', 'Loading '+remaining+' Spotify artists', {next: response.artists.next}))
|
||||
dispatch(uiActions.runProcess('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR', {next: response.artists.next}))
|
||||
} else {
|
||||
dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR'))
|
||||
@ -1390,8 +1404,15 @@ 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'}))
|
||||
var last_run = getState().ui.processes.SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR
|
||||
|
||||
if (!last_run){
|
||||
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR','Loading Spotify albums', {next: 'me/albums?limit=50'}))
|
||||
} else if (last_run.status == 'cancelled'){
|
||||
dispatch(uiActions.updateProcess('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR','Loading Spotify albums', {next: 'me/albums?limit=50'}))
|
||||
} else if (last_run.status == 'finished'){
|
||||
// TODO: do we want to force a refresh?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1409,7 +1430,7 @@ export function getLibraryAlbumsProcessor(data){
|
||||
if (getState().ui.processes['SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR'] !== undefined){
|
||||
var processor = getState().ui.processes['SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR']
|
||||
|
||||
if (processor.cancelling){
|
||||
if (processor.status == 'cancelling'){
|
||||
dispatch(uiActions.processCancelled('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR'))
|
||||
return false
|
||||
}
|
||||
@ -1420,7 +1441,7 @@ export function getLibraryAlbumsProcessor(data){
|
||||
var total = response.total
|
||||
var loaded = getState().spotify.library_albums.length
|
||||
var remaining = total - loaded
|
||||
dispatch(uiActions.updateProcess('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR', 'Loading '+remaining+' Spotify albums'))
|
||||
dispatch(uiActions.updateProcess('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR', 'Loading '+remaining+' Spotify albums', {next: response.next}))
|
||||
dispatch(uiActions.runProcess('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR', {next: response.next}))
|
||||
} else {
|
||||
dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR'))
|
||||
|
||||
@ -156,7 +156,7 @@ export default function reducer(spotify = {}, action){
|
||||
} else {
|
||||
var uris = action.uris
|
||||
}
|
||||
return Object.assign({}, spotify, { library_playlists: uris })
|
||||
return Object.assign({}, spotify, { library_playlists: helpers.removeDuplicates(uris) })
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ARTISTS_LOADED':
|
||||
if (spotify.library_artists){
|
||||
@ -164,7 +164,7 @@ export default function reducer(spotify = {}, action){
|
||||
} else {
|
||||
var uris = action.uris
|
||||
}
|
||||
return Object.assign({}, spotify, { library_artists: uris })
|
||||
return Object.assign({}, spotify, { library_artists: helpers.removeDuplicates(uris) })
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ALBUMS_LOADED':
|
||||
if (spotify.library_albums){
|
||||
@ -172,7 +172,7 @@ export default function reducer(spotify = {}, action){
|
||||
} else {
|
||||
var uris = action.uris
|
||||
}
|
||||
return Object.assign({}, spotify, { library_albums: uris })
|
||||
return Object.assign({}, spotify, { library_albums: helpers.removeDuplicates(uris) })
|
||||
|
||||
case 'SPOTIFY_LIBRARY_TRACKS_LOADED':
|
||||
case 'SPOTIFY_LIBRARY_TRACKS_LOADED_MORE':
|
||||
@ -210,25 +210,6 @@ export default function reducer(spotify = {}, action){
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user