Removing tracks

This commit is contained in:
James Barnsley
2016-11-11 16:47:32 +13:00
parent 3e5a2c84d6
commit 31a1856baf
5 changed files with 57 additions and 8 deletions

View File

@ -0,0 +1,46 @@
var actions = require('./actions.js')
var spotifyActions = require('../spotify/actions.js')
var helpers = require('../../helpers.js')
const UIMiddleware = (function(){
/**
* The actual middleware inteceptor
**/
return store => next => action => {
var state = store.getState();
switch(action.type){
case 'REMOVE_TRACKS_FROM_PLAYLIST':
var playlist = store.getState().ui.playlist
switch( helpers.uriSource( playlist.uri ) ){
case 'spotify':
if( !store.getState().spotify.authorized ){
alert('Must be logged in to Spotify to do this')
return
}
if( !store.getState().spotify.me || store.getState().spotify.me.id != playlist.owner.id ){
alert('You can only modify tracks you own')
return
}
store.dispatch( spotifyActions.deleteTracksFromPlaylist( playlist.uri, playlist.snapshot_id, action.track_indexes ))
break
case 'm3u':
alert('TODO: delete from M3U')
break
}
// This action is irrelevant to us, pass it on to the next middleware
default:
return next(action);
}
}
})();
export default UIMiddleware