Managing playlist tracks
This commit is contained in:
@ -18,7 +18,7 @@ export default class List extends React.Component{
|
|||||||
|
|
||||||
// make sure we haven't clicked a nested link (ie Artist name)
|
// make sure we haven't clicked a nested link (ie Artist name)
|
||||||
if( e.target.tagName.toLowerCase() !== 'a' ){
|
if( e.target.tagName.toLowerCase() !== 'a' ){
|
||||||
hashHistory.push( this.props.link_prefix + encodeURIComponent(uri) );
|
hashHistory.push( this.props.link_prefix + uri );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ const localstorageMiddleware = (function(){
|
|||||||
|
|
||||||
// append our state to a global variable. This gives us access to debug the store at any point
|
// append our state to a global variable. This gives us access to debug the store at any point
|
||||||
window._store = store
|
window._store = store
|
||||||
//console.log(action)
|
console.log(action)
|
||||||
|
|
||||||
switch( action.type ){
|
switch( action.type ){
|
||||||
|
|
||||||
|
|||||||
@ -367,13 +367,13 @@ const MopidyMiddleware = (function(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
store.dispatch({ type: 'PLAYLIST_TRACKS_RESOLVED', tracks: tracks, uri: action.uri })
|
store.dispatch({ type: 'PLAYLIST_TRACKS', tracks: tracks, uri: action.uri })
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'MOPIDY_ADD_PLAYLIST_TRACKS':
|
case 'MOPIDY_ADD_PLAYLIST_TRACKS':
|
||||||
|
|
||||||
instruct( socket, store, 'playlists.lookup', { uri: action.playlist_uri })
|
instruct( socket, store, 'playlists.lookup', { uri: action.uri })
|
||||||
.then( response => {
|
.then( response => {
|
||||||
var tracks = [];
|
var tracks = [];
|
||||||
for( var i = 0; i < action.tracks_uris.length; i++ ){
|
for( var i = 0; i < action.tracks_uris.length; i++ ){
|
||||||
@ -392,7 +392,7 @@ const MopidyMiddleware = (function(){
|
|||||||
|
|
||||||
instruct( socket, store, 'playlists.save', { playlist: playlist } )
|
instruct( socket, store, 'playlists.save', { playlist: playlist } )
|
||||||
.then( response => {
|
.then( response => {
|
||||||
store.dispatch({ type: 'PLAYLIST_TRACKS_ADDED', tracks_uris: action.tracks_uris });
|
store.dispatch({ type: 'PLAYLIST_TRACKS_ADDED', uri: action.uri, tracks_uris: action.tracks_uris });
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
break
|
break
|
||||||
@ -406,7 +406,7 @@ const MopidyMiddleware = (function(){
|
|||||||
var indexes = Object.assign([], action.tracks_indexes)
|
var indexes = Object.assign([], action.tracks_indexes)
|
||||||
indexes.sort(descending);
|
indexes.sort(descending);
|
||||||
|
|
||||||
instruct( socket, store, 'playlists.lookup', { uri: action.playlist_uri })
|
instruct( socket, store, 'playlists.lookup', { uri: action.uri })
|
||||||
.then( response => {
|
.then( response => {
|
||||||
var playlist = Object.assign({}, response)
|
var playlist = Object.assign({}, response)
|
||||||
for( var i = 0; i < indexes.length; i++ ){
|
for( var i = 0; i < indexes.length; i++ ){
|
||||||
@ -414,7 +414,7 @@ const MopidyMiddleware = (function(){
|
|||||||
}
|
}
|
||||||
instruct( socket, store, 'playlists.save', { playlist: playlist } )
|
instruct( socket, store, 'playlists.save', { playlist: playlist } )
|
||||||
.then( response => {
|
.then( response => {
|
||||||
store.dispatch({ type: 'PLAYLIST_TRACKS_REMOVED', tracks_indexes: action.tracks_indexes });
|
store.dispatch({ type: 'PLAYLIST_TRACKS_REMOVED', uri: action.uri, tracks_indexes: action.tracks_indexes });
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
break
|
break
|
||||||
@ -425,7 +425,7 @@ const MopidyMiddleware = (function(){
|
|||||||
var playlist = Object.assign({}, response, { name: action.name })
|
var playlist = Object.assign({}, response, { name: action.name })
|
||||||
instruct( socket, store, 'playlists.save', { playlist: playlist } )
|
instruct( socket, store, 'playlists.save', { playlist: playlist } )
|
||||||
.then( response => {
|
.then( response => {
|
||||||
store.dispatch({ type: 'PLAYLIST_UPDATED', playlist: playlist })
|
store.dispatch({ type: 'PLAYLIST_UPDATED', uri: action.uri, playlist: playlist })
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
break
|
break
|
||||||
@ -464,8 +464,7 @@ const MopidyMiddleware = (function(){
|
|||||||
instruct( socket, store, 'playlists.save', { playlist: playlist } )
|
instruct( socket, store, 'playlists.save', { playlist: playlist } )
|
||||||
.then( response => {
|
.then( response => {
|
||||||
|
|
||||||
// and now re-render our full track references
|
store.dispatch({ type: 'MOPIDY_RESOLVE_PLAYLIST_TRACKS', tracks: playlist.tracks, uri: playlist.uri })
|
||||||
store.dispatch({ type: 'MOPIDY_PLAYLIST_TRACKS', tracks: playlist.tracks })
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
break
|
break
|
||||||
|
|||||||
@ -345,8 +345,6 @@ export function getCategory( id ){
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
console.log(category)
|
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'SPOTIFY_CATEGORY_LOADED',
|
type: 'SPOTIFY_CATEGORY_LOADED',
|
||||||
data: category
|
data: category
|
||||||
@ -857,6 +855,9 @@ function loadNextPlaylistsBatch( dispatch, getState, playlists, lastResponse ){
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// remove our tracklist. It'll overwrite any full records otherwise
|
||||||
|
delete playlist.tracks
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'PLAYLIST_LOADED',
|
type: 'PLAYLIST_LOADED',
|
||||||
playlist: playlist
|
playlist: playlist
|
||||||
@ -898,12 +899,13 @@ export function toggleFollowingPlaylist( uri, method ){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addTracksToPlaylist( playlist_uri, tracks_uris ){
|
export function addTracksToPlaylist( uri, tracks_uris ){
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
sendRequest( dispatch, getState, 'users/'+ helpers.getFromUri('userid',playlist_uri) + '/playlists/'+ helpers.getFromUri('playlistid',playlist_uri) + '/tracks', 'POST', { uris: tracks_uris } )
|
sendRequest( dispatch, getState, 'users/'+ helpers.getFromUri('userid',uri) + '/playlists/'+ helpers.getFromUri('playlistid',uri) + '/tracks', 'POST', { uris: tracks_uris } )
|
||||||
.then( response => {
|
.then( response => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'PLAYLIST_TRACKS_ADDED',
|
type: 'PLAYLIST_TRACKS_ADDED',
|
||||||
|
uri: uri,
|
||||||
tracks_uris: tracks_uris,
|
tracks_uris: tracks_uris,
|
||||||
snapshot_id: response.snapshot_id
|
snapshot_id: response.snapshot_id
|
||||||
});
|
});
|
||||||
@ -917,6 +919,7 @@ export function deleteTracksFromPlaylist( uri, snapshot_id, tracks_indexes ){
|
|||||||
.then( response => {
|
.then( response => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'PLAYLIST_TRACKS_REMOVED',
|
type: 'PLAYLIST_TRACKS_REMOVED',
|
||||||
|
uri: uri,
|
||||||
tracks_indexes: tracks_indexes,
|
tracks_indexes: tracks_indexes,
|
||||||
snapshot_id: response.snapshot_id
|
snapshot_id: response.snapshot_id
|
||||||
});
|
});
|
||||||
@ -930,6 +933,7 @@ export function reorderPlaylistTracks( uri, range_start, range_length, insert_be
|
|||||||
.then( response => {
|
.then( response => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'PLAYLIST_TRACKS_REORDERED',
|
type: 'PLAYLIST_TRACKS_REORDERED',
|
||||||
|
uri: uri,
|
||||||
range_start: range_start,
|
range_start: range_start,
|
||||||
range_length: range_length,
|
range_length: range_length,
|
||||||
insert_before: insert_before,
|
insert_before: insert_before,
|
||||||
|
|||||||
@ -18,8 +18,6 @@ const SpotifyMiddleware = (function(){
|
|||||||
break
|
break
|
||||||
|
|
||||||
case 'SPOTIFY_CREATE_PLAYLIST':
|
case 'SPOTIFY_CREATE_PLAYLIST':
|
||||||
var playlist = state.ui.playlist
|
|
||||||
|
|
||||||
if( !store.getState().spotify.authorized ){
|
if( !store.getState().spotify.authorized ){
|
||||||
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
|
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
|
||||||
return
|
return
|
||||||
@ -28,7 +26,7 @@ const SpotifyMiddleware = (function(){
|
|||||||
break
|
break
|
||||||
|
|
||||||
case 'SPOTIFY_REMOVE_PLAYLIST_TRACKS':
|
case 'SPOTIFY_REMOVE_PLAYLIST_TRACKS':
|
||||||
var playlist = state.ui.playlist
|
var playlist = state.ui.playlists[action.uri]
|
||||||
|
|
||||||
if( !store.getState().spotify.authorized ){
|
if( !store.getState().spotify.authorized ){
|
||||||
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
|
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
|
||||||
|
|||||||
@ -147,39 +147,39 @@ export function createPlaylist( scheme, name, is_public = false ){
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeTracksFromPlaylist( playlist_uri, tracks_indexes ){
|
export function removeTracksFromPlaylist( uri, tracks_indexes ){
|
||||||
switch( helpers.uriSource( playlist_uri ) ){
|
switch( helpers.uriSource( uri ) ){
|
||||||
|
|
||||||
case 'spotify':
|
case 'spotify':
|
||||||
return {
|
return {
|
||||||
type: 'SPOTIFY_REMOVE_PLAYLIST_TRACKS',
|
type: 'SPOTIFY_REMOVE_PLAYLIST_TRACKS',
|
||||||
playlist_uri: playlist_uri,
|
uri: uri,
|
||||||
tracks_indexes: tracks_indexes
|
tracks_indexes: tracks_indexes
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'm3u':
|
case 'm3u':
|
||||||
return {
|
return {
|
||||||
type: 'MOPIDY_REMOVE_PLAYLIST_TRACKS',
|
type: 'MOPIDY_REMOVE_PLAYLIST_TRACKS',
|
||||||
playlist_uri: playlist_uri,
|
uri: uri,
|
||||||
tracks_indexes: tracks_indexes
|
tracks_indexes: tracks_indexes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addTracksToPlaylist( playlist_uri, tracks_uris ){
|
export function addTracksToPlaylist( uri, tracks_uris ){
|
||||||
switch( helpers.uriSource( playlist_uri ) ){
|
switch( helpers.uriSource( uri ) ){
|
||||||
|
|
||||||
case 'spotify':
|
case 'spotify':
|
||||||
return {
|
return {
|
||||||
type: 'SPOTIFY_ADD_PLAYLIST_TRACKS',
|
type: 'SPOTIFY_ADD_PLAYLIST_TRACKS',
|
||||||
playlist_uri: playlist_uri,
|
uri: uri,
|
||||||
tracks_uris: tracks_uris
|
tracks_uris: tracks_uris
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'm3u':
|
case 'm3u':
|
||||||
return {
|
return {
|
||||||
type: 'MOPIDY_ADD_PLAYLIST_TRACKS',
|
type: 'MOPIDY_ADD_PLAYLIST_TRACKS',
|
||||||
playlist_uri: playlist_uri,
|
uri: uri,
|
||||||
tracks_uris: tracks_uris
|
tracks_uris: tracks_uris
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -253,17 +253,20 @@ export default function reducer(ui = {}, action){
|
|||||||
return Object.assign({}, ui, { playlists: playlists });
|
return Object.assign({}, ui, { playlists: playlists });
|
||||||
|
|
||||||
case 'PLAYLIST_TRACKS_REMOVED':
|
case 'PLAYLIST_TRACKS_REMOVED':
|
||||||
var tracks = Object.assign([], ui.playlist.tracks)
|
var playlists = Object.assign([], ui.playlists)
|
||||||
|
var playlist = Object.assign({}, playlists[action.uri])
|
||||||
|
var tracks = Object.assign([], playlist.tracks)
|
||||||
var indexes = action.tracks_indexes.reverse()
|
var indexes = action.tracks_indexes.reverse()
|
||||||
for( var i = 0; i < indexes.length; i++ ){
|
for( var i = 0; i < indexes.length; i++ ){
|
||||||
tracks.splice( indexes[i], 1 )
|
tracks.splice( indexes[i], 1 )
|
||||||
}
|
}
|
||||||
var snapshot_id = null
|
var snapshot_id = null
|
||||||
if( action.snapshot_id ) snapshot_id = action.snapshot_id
|
if( action.snapshot_id ) snapshot_id = action.snapshot_id
|
||||||
var playlist = Object.assign({}, ui.playlist, { tracks: tracks, snapshot_id: snapshot_id })
|
Object.assign(playlist, { tracks: tracks, snapshot_id: snapshot_id })
|
||||||
return Object.assign({}, ui, { playlist: playlist });
|
playlists[action.uri] = playlist
|
||||||
|
return Object.assign({}, ui, { playlists: playlists });
|
||||||
|
|
||||||
case 'PLAYLIST_TRACKS_RESOLVED':
|
case 'PLAYLIST_TRACKS':
|
||||||
var playlists = Object.assign([], ui.playlists)
|
var playlists = Object.assign([], ui.playlists)
|
||||||
var playlist = Object.assign({}, playlists[action.uri], { tracks: action.tracks })
|
var playlist = Object.assign({}, playlists[action.uri], { tracks: action.tracks })
|
||||||
|
|
||||||
@ -271,9 +274,9 @@ export default function reducer(ui = {}, action){
|
|||||||
return Object.assign({}, ui, { playlists: playlists });
|
return Object.assign({}, ui, { playlists: playlists });
|
||||||
|
|
||||||
case 'PLAYLIST_TRACKS_REORDERED':
|
case 'PLAYLIST_TRACKS_REORDERED':
|
||||||
var snapshot_id = null
|
var playlists = Object.assign([], ui.playlists)
|
||||||
if( action.snapshot_id ) snapshot_id = action.snapshot_id
|
var playlist = Object.assign({}, playlists[action.uri])
|
||||||
var tracks = Object.assign([], ui.playlist.tracks)
|
var tracks = Object.assign([], playlist.tracks)
|
||||||
|
|
||||||
// handle insert_before offset if we're moving BENEATH where we're slicing tracks
|
// handle insert_before offset if we're moving BENEATH where we're slicing tracks
|
||||||
var insert_before = action.insert_before
|
var insert_before = action.insert_before
|
||||||
@ -287,8 +290,11 @@ export default function reducer(ui = {}, action){
|
|||||||
tracks.splice(insert_before, 0, tracks_to_move[i])
|
tracks.splice(insert_before, 0, tracks_to_move[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
var playlist = Object.assign({}, ui.playlist, { snapshot_id: snapshot_id, tracks: tracks })
|
var snapshot_id = null
|
||||||
return Object.assign({}, ui, { playlist: playlist });
|
if( action.snapshot_id ) snapshot_id = action.snapshot_id
|
||||||
|
Object.assign(playlist, { tracks: tracks, snapshot_id: snapshot_id })
|
||||||
|
playlists[action.uri] = playlist
|
||||||
|
return Object.assign({}, ui, { playlists: playlists });
|
||||||
|
|
||||||
case 'PLAYLIST_FOLLOWING_LOADED':
|
case 'PLAYLIST_FOLLOWING_LOADED':
|
||||||
var playlists = Object.assign([], ui.playlists)
|
var playlists = Object.assign([], ui.playlists)
|
||||||
|
|||||||
Reference in New Issue
Block a user