More universal processor style
This commit is contained in:
@ -64,24 +64,12 @@ export function enqueueURIs(uris, from_uri = null, next = false, at_position = n
|
||||
}
|
||||
}
|
||||
|
||||
export function enqueueURIsCancel(){
|
||||
return {
|
||||
type: 'MOPIDY_ENQUEUE_URIS_CANCEL'
|
||||
}
|
||||
}
|
||||
|
||||
export function enqueueURIsBatchDone(){
|
||||
return {
|
||||
type: 'MOPIDY_ENQUEUE_URIS_BATCH_DONE'
|
||||
}
|
||||
}
|
||||
|
||||
export function enqueueUrisProcessor(){
|
||||
return {
|
||||
type: 'MOPIDY_ENQUEUE_URIS_PROCESSOR'
|
||||
}
|
||||
}
|
||||
|
||||
export function playPlaylist(uri){
|
||||
return {
|
||||
type: 'MOPIDY_PLAY_PLAYLIST',
|
||||
|
||||
@ -272,7 +272,6 @@ const MopidyMiddleware = (function(){
|
||||
// make sure we didn't get this playlist from Mopidy-Spotify
|
||||
// if we did, we'd have a cached version on server so no need to fetch
|
||||
if (!store.getState().core.playlists[action.uri].is_mopidy){
|
||||
store.dispatch(uiActions.startProcess('MOPIDY_ENQUEUE_URIS', 'Fetching tracks'))
|
||||
store.dispatch(spotifyActions.getAllPlaylistTracks(action.uri))
|
||||
break
|
||||
}
|
||||
@ -280,7 +279,6 @@ const MopidyMiddleware = (function(){
|
||||
// it's a spotify playlist that we haven't loaded
|
||||
// we need to fetch via HTTP API to avoid timeout
|
||||
} else if (helpers.uriSource(action.uri) == 'spotify' && store.getState().spotify.enabled){
|
||||
store.dispatch(uiActions.startProcess('MOPIDY_ENQUEUE_URIS', 'Fetching tracks'))
|
||||
store.dispatch(spotifyActions.getAllPlaylistTracks(action.uri))
|
||||
break
|
||||
|
||||
@ -329,7 +327,7 @@ const MopidyMiddleware = (function(){
|
||||
next(action)
|
||||
|
||||
// start our processor
|
||||
store.dispatch(mopidyActions.enqueueUrisProcessor())
|
||||
store.dispatch(uiActions.startProcess('MOPIDY_ENQUEUE_URIS_PROCESSOR', 'Adding '+action.uris.length+' URI(s)'))
|
||||
break
|
||||
|
||||
case 'MOPIDY_ENQUEUE_URIS_PROCESSOR':
|
||||
@ -343,11 +341,11 @@ const MopidyMiddleware = (function(){
|
||||
for (var i = 0; i < batches.length; i++){
|
||||
total_uris += batches[i].uris.length
|
||||
}
|
||||
store.dispatch(uiActions.startProcess('MOPIDY_ENQUEUE_URIS', 'Adding '+total_uris+' URI(s)'))
|
||||
store.dispatch(uiActions.updateProcess('MOPIDY_ENQUEUE_URIS_PROCESSOR', 'Adding '+total_uris+' URI(s)'))
|
||||
|
||||
// no batches means we're done here
|
||||
} else {
|
||||
store.dispatch(uiActions.stopProcess('MOPIDY_ENQUEUE_URIS'))
|
||||
store.dispatch(uiActions.processFinished('MOPIDY_ENQUEUE_URIS_PROCESSOR'))
|
||||
break
|
||||
}
|
||||
|
||||
@ -400,7 +398,7 @@ const MopidyMiddleware = (function(){
|
||||
setTimeout(
|
||||
function(){
|
||||
store.dispatch(mopidyActions.enqueueURIsBatchDone())
|
||||
store.dispatch(mopidyActions.enqueueUrisProcessor())
|
||||
store.dispatch(uiActions.runProcess(action.type))
|
||||
},
|
||||
100
|
||||
)
|
||||
@ -846,7 +844,7 @@ const MopidyMiddleware = (function(){
|
||||
});
|
||||
|
||||
// Start our process to load the full album objects
|
||||
store.dispatch(mopidyActions.runProcessor('MOPIDY_LIBRARY_ALBUMS_PROCESSOR'));
|
||||
store.dispatch(uiActions.runProcess('MOPIDY_LIBRARY_ALBUMS_PROCESSOR'));
|
||||
})
|
||||
break;
|
||||
|
||||
@ -856,7 +854,7 @@ const MopidyMiddleware = (function(){
|
||||
var processor = store.getState().ui.processes['MOPIDY_LIBRARY_ALBUMS']
|
||||
|
||||
if (processor.cancelling){
|
||||
store.dispatch(uiActions.stopProcess('MOPIDY_LIBRARY_ALBUMS'))
|
||||
store.dispatch(uiActions.processFinished('MOPIDY_LIBRARY_ALBUMS'))
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -876,7 +874,7 @@ const MopidyMiddleware = (function(){
|
||||
if (to_load.length > 0){
|
||||
store.dispatch(mopidyActions.getAlbums(to_load, 'MOPIDY_LIBRARY_ALBUMS_PROCESSOR'))
|
||||
} else {
|
||||
store.dispatch(uiActions.stopProcess('MOPIDY_LIBRARY_ALBUMS'))
|
||||
store.dispatch(uiActions.processFinished('MOPIDY_LIBRARY_ALBUMS'))
|
||||
}
|
||||
|
||||
break
|
||||
|
||||
@ -104,15 +104,16 @@ export default function reducer(mopidy = {}, action){
|
||||
enqueue_uris_batches: batches
|
||||
});
|
||||
|
||||
case 'MOPIDY_ENQUEUE_URIS_CANCEL':
|
||||
case 'MOPIDY_ENQUEUE_URIS_PROCESSOR_CANCEL':
|
||||
return Object.assign({}, mopidy, {
|
||||
enqueue_uris_batches: []
|
||||
});
|
||||
|
||||
case 'MOPIDY_ENQUEUE_URIS_BATCH_DONE':
|
||||
if (!mopidy.enqueue_uris_batches || mopidy.enqueue_uris_batches.length <= 0){
|
||||
|
||||
// Batches empty, so we've been cancelled
|
||||
var batches = []
|
||||
console.error('Cannot remove batch when queue empty',action)
|
||||
} else {
|
||||
var batches = mopidy.enqueue_uris_batches
|
||||
batches.shift()
|
||||
|
||||
@ -176,6 +176,20 @@ export function startProcess(key,content){
|
||||
}
|
||||
}
|
||||
|
||||
export function updateProcess(key,content){
|
||||
return {
|
||||
type: 'UPDATE_PROCESS',
|
||||
key: key,
|
||||
content: content
|
||||
}
|
||||
}
|
||||
|
||||
export function runProcess(key){
|
||||
return {
|
||||
type: key
|
||||
}
|
||||
}
|
||||
|
||||
export function cancelProcess(key){
|
||||
return {
|
||||
type: 'CANCEL_PROCESS',
|
||||
@ -183,9 +197,9 @@ export function cancelProcess(key){
|
||||
}
|
||||
}
|
||||
|
||||
export function stopProcess(key){
|
||||
export function processFinished(key){
|
||||
return {
|
||||
type: 'STOP_PROCESS',
|
||||
type: 'PROCESS_FINISHED',
|
||||
key: key
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,13 +122,17 @@ const UIMiddleware = (function(){
|
||||
next(action)
|
||||
break
|
||||
|
||||
case 'START_PROCESS':
|
||||
store.dispatch({
|
||||
type: action.key
|
||||
})
|
||||
next(action)
|
||||
break
|
||||
|
||||
case 'CANCEL_PROCESS':
|
||||
if (action.key == 'MOPIDY_ENQUEUE_URIS'){
|
||||
store.dispatch(mopidyActions.enqueueURIsCancel())
|
||||
}
|
||||
if (action.key == 'MOPIDY_LIBRARY_ALBUMS_PROCESSOR'){
|
||||
store.dispatch(mopidyActions.cancelProcessor(action.key))
|
||||
}
|
||||
store.dispatch({
|
||||
type: action.key+'_CANCEL'
|
||||
})
|
||||
next(action)
|
||||
break
|
||||
|
||||
|
||||
@ -126,6 +126,7 @@ export default function reducer(ui = {}, action){
|
||||
return Object.assign({}, ui, {load_queue: load_queue})
|
||||
|
||||
case 'START_PROCESS':
|
||||
case 'UPDATE_PROCESS':
|
||||
var processes = Object.assign({}, (ui.processes ? ui.processes : []))
|
||||
processes[action.key] = {
|
||||
key: action.key,
|
||||
@ -146,7 +147,7 @@ export default function reducer(ui = {}, action){
|
||||
}
|
||||
return Object.assign({}, ui, {processes: processes})
|
||||
|
||||
case 'STOP_PROCESS':
|
||||
case 'PROCESS_FINISHED':
|
||||
var processes = Object.assign({}, (ui.processes ? ui.processes : {}))
|
||||
if (processes[action.key]){
|
||||
delete processes[action.key]
|
||||
|
||||
Reference in New Issue
Block a user