Loading mopidy playlist and tracks

This commit is contained in:
James Barnsley
2016-11-01 11:49:04 +13:00
parent b302cd2ac0
commit 569121c71d
8 changed files with 379 additions and 108 deletions

View File

@ -103,3 +103,10 @@ export function getBrowse( uri ){
}
}
export function getPlaylist( uri ){
return {
type: 'MOPIDY_PLAYLIST',
data: { uri: uri }
}
}

View File

@ -154,6 +154,47 @@ const MopidyMiddleware = (function(){
})
break;
case 'MOPIDY_PLAYLIST':
instruct( socket, store, 'playlists.lookup', action.data )
.then( response => {
var playlist = response;
playlist.tracks = {
items: response.tracks,
total: response.tracks.length
}
var uris = [];
for( var i = 0; i < playlist.tracks.items.length; i++ ){
uris.push( playlist.tracks.items[i].uri );
}
instruct( socket, store, 'library.lookup', { uris: uris } )
.then( response => {
for(var uri in response){
if (response.hasOwnProperty(uri)) {
var track = response[uri][0];
// find the track reference, and drop in the full track data
function getByURI( trackReference ){
return track.uri == trackReference.uri
}
var trackReferences = playlist.tracks.items.filter(getByURI);
// there could be multiple instances of this track, so accommodate this
for( var j = 0; j < trackReferences.length; j++){
var key = playlist.tracks.items.indexOf( trackReferences[j] );
playlist.tracks.items[ key ] = track;
}
}
}
store.dispatch({ type: 'MOPIDY_PLAYLIST_LOADED', data: playlist });
})
})
break;
// This action is irrelevant to us, pass it on to the next middleware
default:
return next(action);

View File

@ -77,6 +77,11 @@ export default function reducer(mopidy = {}, action){
browse: action.data
});
case 'MOPIDY_PLAYLIST_LOADED':
return Object.assign({}, mopidy, {
playlist: action.data
});
default:
return mopidy
}