From 4946d21850d5db7db24cd34f442118c93bf83432 Mon Sep 17 00:00:00 2001 From: James Barnsley Date: Fri, 5 May 2017 04:06:06 +1200 Subject: [PATCH] Cancelling of Adding URIs --- src/js/services/mopidy/actions.js | 6 ++++++ src/js/services/mopidy/middleware.js | 11 ++++++++--- src/js/services/mopidy/reducer.js | 5 +++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/js/services/mopidy/actions.js b/src/js/services/mopidy/actions.js index cc42d5d3..54fca06a 100755 --- a/src/js/services/mopidy/actions.js +++ b/src/js/services/mopidy/actions.js @@ -67,6 +67,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' diff --git a/src/js/services/mopidy/middleware.js b/src/js/services/mopidy/middleware.js index cd9351d4..cf7b8a2e 100755 --- a/src/js/services/mopidy/middleware.js +++ b/src/js/services/mopidy/middleware.js @@ -284,7 +284,6 @@ const MopidyMiddleware = (function(){ break case 'MOPIDY_ENQUEUE_URIS': - console.log(action) // split into batches var uris = Object.assign([], action.uris) @@ -298,7 +297,7 @@ const MopidyMiddleware = (function(){ }) } - // pass off this modified action to the reducer (and other middleware) + // pass this modified action to the reducer (and other middleware) action.batches = batches next(action) @@ -307,7 +306,6 @@ const MopidyMiddleware = (function(){ break case 'MOPIDY_ENQUEUE_URIS_PROCESSOR': - console.log(action) // make sure we have some uris in the queue if (store.getState().mopidy.enqueue_uris_batches && store.getState().mopidy.enqueue_uris_batches.length > 0){ @@ -366,6 +364,13 @@ const MopidyMiddleware = (function(){ break + case 'CANCEL_PROCESS': + if (action.key == 'MOPIDY_ENQUEUE_URIS'){ + store.dispatch(mopidyActions.enqueueURIsCancel()) + } + next(action) + break + case 'MOPIDY_PLAY_URIS': // stop the radio diff --git a/src/js/services/mopidy/reducer.js b/src/js/services/mopidy/reducer.js index 92d0e0c5..7a84c167 100755 --- a/src/js/services/mopidy/reducer.js +++ b/src/js/services/mopidy/reducer.js @@ -99,6 +99,11 @@ export default function reducer(mopidy = {}, action){ enqueue_uris_batches: batches }); + case 'MOPIDY_ENQUEUE_URIS_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){ var batches = []