Loading library albums as process; Processes loader for less jammy animation

This commit is contained in:
James Barnsley
2017-08-10 12:00:08 +12:00
parent fcf44d0b28
commit fd46929ac3
11 changed files with 151 additions and 287 deletions

View File

@ -217,10 +217,11 @@ export function getAlbum( uri ){
}
}
export function getAlbums( uris ){
export function getAlbums(uris, processor = null){
return {
type: 'MOPIDY_GET_ALBUMS',
uris: uris
uris: uris,
processor: processor
}
}
@ -230,6 +231,18 @@ export function getLibraryAlbums(){
}
}
export function runProcessor(processor){
return {
type: processor
}
}
export function cancelProcessor(processor){
return {
type: processor+'_CANCEL'
}
}
/**
* Searching

View File

@ -840,22 +840,47 @@ const MopidyMiddleware = (function(){
.then( response => {
if (response.length <= 0) return
var uris = helpers.arrayOf('uri',response)
/*
store.dispatch({
type: 'MOPIDY_GET_ALBUMS',
uris: uris//.slice(0,50) THIS PAGINATES REQUESTS. Slow servers might need this...
});
*/
store.dispatch({
type: 'LIBRARY_ALBUMS_LOADED',
uris: uris
uris: helpers.arrayOf('uri',response)
});
// Start our process to load the full album objects
store.dispatch(mopidyActions.runProcessor('MOPIDY_LIBRARY_ALBUMS_PROCESSOR'));
})
break;
case 'MOPIDY_LIBRARY_ALBUMS_PROCESSOR':
if (store.getState().ui.processes['MOPIDY_LIBRARY_ALBUMS'] !== undefined){
var processor = store.getState().ui.processes['MOPIDY_LIBRARY_ALBUMS']
if (processor.cancelling){
store.dispatch(uiActions.stopProcess('MOPIDY_LIBRARY_ALBUMS'))
return false
}
}
store.dispatch(uiActions.startProcess('MOPIDY_LIBRARY_ALBUMS', 'Loading album library'))
// Figure out the remaining items
var library_uris = store.getState().core.library_albums
var to_load = []
for (var i = 0; i < library_uris.length && to_load.length < 50; i++){
var uri = library_uris[i]
if (helpers.uriSource(uri) == 'local' && store.getState().core.albums[uri] === undefined){
to_load.push(uri)
}
}
if (to_load.length > 0){
store.dispatch(mopidyActions.getAlbums(to_load, 'MOPIDY_LIBRARY_ALBUMS_PROCESSOR'))
} else {
store.dispatch(uiActions.stopProcess('MOPIDY_LIBRARY_ALBUMS'))
}
break
case 'MOPIDY_GET_ALBUMS':
instruct( socket, store, 'library.lookup', { uris: action.uris } )
.then( response => {
@ -883,7 +908,19 @@ const MopidyMiddleware = (function(){
store.dispatch({
type: 'ALBUMS_LOADED',
albums: albums
});
})
// Re-run any consequential processes in 100ms. This allows a small window for other
// server requests before our next batch. It's a little crude but it means the server isn't
// locked until we're completely done.
if (action.processor){
setTimeout(
function(){
store.dispatch(mopidyActions.runProcessor(action.processor))
},
100
)
}
})
break;

View File

@ -126,6 +126,9 @@ const UIMiddleware = (function(){
if (action.key == 'MOPIDY_ENQUEUE_URIS'){
store.dispatch(mopidyActions.enqueueURIsCancel())
}
if (action.key == 'MOPIDY_LIBRARY_ALBUMS_PROCESSOR'){
store.dispatch(mopidyActions.cancelProcessor(action.key))
}
next(action)
break