Reordering local playlist tracks; Lazy-loading track details

This commit is contained in:
James Barnsley
2016-11-16 13:13:35 +13:00
parent af32551ddf
commit 98770441cc
8 changed files with 123 additions and 59 deletions

View File

@ -59,22 +59,23 @@ export function dragEnd(){
return { type: 'DRAG_END' }
}
export function reorderTracks( context, indexes, destination_index ){
console.log('uiActions.reorderTracks', context, indexes, destination_index)
switch( context ){
export function reorderPlaylistTracks( uri, indexes, to_index ){
switch( helpers.uriSource( uri ) ){
case 'queue':
case 'spotify':
return {
type: 'MOPIDY_REORDER_TRACKLIST',
type: 'SPOTIFY_REORDER_PLAYLIST_TRACKS',
uri: uri,
indexes: indexes,
destination_index: destination_index
to_index: to_index
}
case 'editable-playlist':
case 'm3u':
return {
type: 'SPOTIFY_REORDER_TRACKLIST',
type: 'MOPIDY_REORDER_PLAYLIST_TRACKS',
uri: uri,
indexes: indexes,
destination_index: destination_index
to_index: to_index
}
}
}

View File

@ -221,20 +221,28 @@ export default function reducer(ui = {}, action){
case 'PLAYLIST_TRACKS_REMOVED':
var tracks = Object.assign([], ui.playlist.tracks)
for( var i = 0; i < action.tracks_indexes.length; i++ ){
tracks.splice( action.tracks_indexes[i], 1 )
var indexes = action.tracks_indexes.reverse()
for( var i = 0; i < indexes.length; i++ ){
tracks.splice( indexes[i], 1 )
}
var snapshot_id = null
if( action.snapshot_id ) snapshot_id = action.snapshot_id
var playlist = Object.assign({}, ui.playlist, { tracks: tracks, snapshot_id: snapshot_id })
return Object.assign({}, ui, { playlist: playlist });
case 'PLAYLIST_TRACKS_LOADED':
var playlist = Object.assign({}, ui.playlist, { tracks: action.tracks })
return Object.assign({}, ui, { playlist: playlist });
case 'PLAYLIST_TRACKS_REORDERED':
var snapshot_id = null
if( action.snapshot_id ) snapshot_id = action.snapshot_id
var playlist = Object.assign({}, ui.playlist, { tracks: action.tracks, snapshot_id: snapshot_id })
return Object.assign({}, ui, { playlist: playlist });
/**
* Library Playlists
*
* TODO: Map sources and merge any replicated URIS
*
**/
case 'MOPIDY_PLAYLISTS_LOADED':