diff --git a/src/js/components/ContextMenu.js b/src/js/components/ContextMenu.js
index cacadd05..56e55114 100755
--- a/src/js/components/ContextMenu.js
+++ b/src/js/components/ContextMenu.js
@@ -139,7 +139,7 @@ class ContextMenu extends React.Component{
return (helpers.uriSource(this.props.menu.items[0].uri) == 'spotify')
}
- toggleInLibrary(in_library){
+ toggleInLibrary(e, in_library){
this.props.uiActions.hideContextMenu()
if (in_library){
this.props.spotifyActions.following(this.props.menu.items[0].uri, 'DELETE')
@@ -148,13 +148,13 @@ class ContextMenu extends React.Component{
}
}
- playQueueItem(){
+ playQueueItem(e){
this.props.uiActions.hideContextMenu()
var tracks = this.props.menu.items;
this.props.mopidyActions.changeTrack( tracks[0].tlid )
}
- removeFromQueue(){
+ removeFromQueue(e){
this.props.uiActions.hideContextMenu()
var tracks = this.props.menu.items;
var tracks_tlids = [];
@@ -164,37 +164,32 @@ class ContextMenu extends React.Component{
this.props.mopidyActions.removeTracks( tracks_tlids );
}
- playURIs(){
+ playURIs(e){
this.props.uiActions.hideContextMenu()
this.props.mopidyActions.playURIs(this.props.menu.uris, this.props.menu.tracklist_uri)
}
- playURIsNext(){
+ addToQueue(e, next = false){
this.props.uiActions.hideContextMenu()
- this.props.mopidyActions.enqueueURIsNext(this.props.menu.uris, this.props.menu.tracklist_uri)
+ this.props.mopidyActions.enqueueURIs(this.props.menu.uris, this.props.menu.tracklist_uri, next)
}
- addToQueue(){
- this.props.uiActions.hideContextMenu()
- this.props.mopidyActions.enqueueURIs(this.props.menu.uris, this.props.menu.tracklist_uri)
- }
-
- addTracksToPlaylist(playlist_uri){
+ addTracksToPlaylist(e, playlist_uri){
this.props.uiActions.hideContextMenu()
this.props.uiActions.addTracksToPlaylist(playlist_uri, this.props.menu.uris)
}
- removeFromPlaylist(){
+ removeFromPlaylist(e){
this.props.uiActions.hideContextMenu()
this.props.uiActions.removeTracksFromPlaylist(this.props.menu.tracklist_uri, this.props.menu.indexes)
}
- startRadio(){
+ startRadio(e){
this.props.uiActions.hideContextMenu()
this.props.pusherActions.startRadio(this.props.menu.uris)
}
- goToArtist(){
+ goToArtist(e){
if (!this.props.menu.items || this.props.menu.items.length <= 0 || !this.props.menu.items[0].artists || this.props.menu.items[0].artists.length <= 0){
return null
} else {
@@ -203,7 +198,7 @@ class ContextMenu extends React.Component{
}
}
- goToUser(){
+ goToUser(e){
if (!this.props.menu.items || this.props.menu.items.length <= 0){
return null
} else {
@@ -223,7 +218,7 @@ class ContextMenu extends React.Component{
this.props.uiActions.hideContextMenu()
}
- closeAndDeselectTracks(){
+ closeAndDeselectTracks(e){
this.props.uiActions.hideContextMenu();
// TODO
}
@@ -341,7 +336,7 @@ class ContextMenu extends React.Component{
var play_uris_next = (
- this.playURIsNext(e)}>
+ this.addToQueue(e, true)}>
Play next
@@ -367,7 +362,7 @@ class ContextMenu extends React.Component{
var toggle_in_library = (
- this.toggleInLibrary(context.in_library)}>
+ this.toggleInLibrary(e, context.in_library)}>
{context.in_library ? 'Remove from library' : 'Add to library'}
diff --git a/src/js/services/mopidy/actions.js b/src/js/services/mopidy/actions.js
index 00c2f2bf..847da96f 100755
--- a/src/js/services/mopidy/actions.js
+++ b/src/js/services/mopidy/actions.js
@@ -57,20 +57,12 @@ export function playURIs( uris, from_uri = null ){
}
}
-export function enqueueURIsNext( uris, from_uri = null ){
- if( typeof(uris) !== 'object' ) uris = [uris]
- return {
- type: 'MOPIDY_ENQUEUE_URIS_NEXT',
- uris: uris,
- from_uri: from_uri
- }
-}
-
-export function enqueueURIs( uris, from_uri = null, at_position = false ){
+export function enqueueURIs( uris, from_uri = null, next = false, at_position = null ){
return {
type: 'MOPIDY_ENQUEUE_URIS',
uris: uris,
at_position: at_position,
+ next: next,
from_uri: from_uri
}
}
diff --git a/src/js/services/mopidy/middleware.js b/src/js/services/mopidy/middleware.js
index e75a3c06..c8bf7490 100755
--- a/src/js/services/mopidy/middleware.js
+++ b/src/js/services/mopidy/middleware.js
@@ -222,35 +222,8 @@ const MopidyMiddleware = (function(){
break;
case 'MOPIDY_ENQUEUE_URIS':
-
- // create batches of 20 uris to load
- var all_uris = Object.assign([], action.uris)
- var batched_uris = []
- while (all_uris.length > 0){
- batched_uris.push( all_uris.splice(0,20) )
- }
-
- // run each batch
- for (var i = 0; i < batched_uris.length; i++){
- var value = { uris: batched_uris[i] }
- if (action.at_position){
- value.at_position = action.at_position
- }
-
- instruct( socket, store, 'tracklist.add', value )
- .then( response => {
- var tlids = []
- for (var i = 0; i < response.length; i++){
- tlids.push(response[i].tlid)
- }
- store.dispatch( pusherActions.addQueueMetadata(tlids, action.from_uri) )
- console.info('Added '+tlids.length+' URI(s) to queue')
- })
- }
- break
-
- case 'MOPIDY_ENQUEUE_URIS_NEXT':
-
+ var uris_added = 0
+ var remaining_uris = Object.assign([], action.uris)
var current_track = store.getState().ui.current_track
var current_tracklist = store.getState().ui.current_tracklist
var current_track_index = -1
@@ -264,18 +237,46 @@ const MopidyMiddleware = (function(){
}
}
- var at_position = null
- if( current_track_index > -1 ) at_position = current_track_index + 1
+ let process_batch = function(){
+ var params = {uris: remaining_uris.splice(0,10)}
+ if (action.next && current_track_index > -1){
+ params.at_position = current_track_index + uris_added + 1
+ } else if (action.at_position){
+ params.at_position = action.at_position
+ }
+
+ instruct(socket, store, 'tracklist.add', params)
+ .then( response => {
+
+ // append our counter
+ uris_added += response.length
+
+ // add metadata to queue
+ var tlids = []
+ for (var i = 0; i < response.length; i++){
+ tlids.push(response[i].tlid)
+ }
+ store.dispatch( pusherActions.addQueueMetadata(tlids, action.from_uri) )
+
+ console.info('Added '+tlids.length+' URI(s) to queue')
+
+ // still more URIs? run again in 0.8s
+ // this gives our server time to handle other requests
+ // crude, but prevents locking the server
+ if (remaining_uris.length > 0){
+ setTimeout(
+ function(){
+ process_batch()
+ },
+ 800
+ )
+ }
+ })
+ }
+
+ // start processing
+ process_batch()
- instruct( socket, store, 'tracklist.add', { uris: action.uris, at_position: at_position } )
- .then( response => {
- var tlids = []
- for (var i = 0; i < response.length; i++){
- tlids.push(response[i].tlid)
- }
- store.dispatch( pusherActions.addQueueMetadata(tlids, action.from_uri) )
- store.dispatch( uiActions.createNotification('Added '+tlids.length+' URI(s) to queue') )
- })
break
case 'MOPIDY_PLAY_URIS':