Notifications for events
This commit is contained in:
@ -160,10 +160,6 @@ export function connect(){
|
||||
* Handle authorization process
|
||||
**/
|
||||
|
||||
export function startAuthorization(){
|
||||
return { type: 'SPOTIFY_START_AUTHORIZATION' }
|
||||
}
|
||||
|
||||
export function authorizationGranted( data ){
|
||||
data.token_expiry = new Date().getTime() + data.expires_in;
|
||||
return { type: 'SPOTIFY_AUTHORIZATION_GRANTED', data: data }
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
|
||||
|
||||
var actions = require('./actions.js')
|
||||
var spotifyActions = require('./actions.js')
|
||||
var uiActions = require('../ui/actions.js')
|
||||
|
||||
const SpotifyMiddleware = (function(){
|
||||
|
||||
@ -13,17 +14,18 @@ const SpotifyMiddleware = (function(){
|
||||
switch(action.type){
|
||||
|
||||
case 'SPOTIFY_CONNECT':
|
||||
store.dispatch( actions.getMe() )
|
||||
|
||||
store.dispatch( spotifyActions.getMe() )
|
||||
break
|
||||
|
||||
|
||||
case 'SPOTIFY_CREATE_PLAYLIST':
|
||||
var playlist = state.ui.playlist
|
||||
|
||||
if( !store.getState().spotify.authorized ){
|
||||
alert('Must be logged in to Spotify to do this')
|
||||
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
|
||||
return
|
||||
}
|
||||
store.dispatch( actions.createPlaylist( action.name, action.is_private ))
|
||||
store.dispatch( spotifyActions.createPlaylist( action.name, action.is_private ))
|
||||
break
|
||||
|
||||
|
||||
@ -31,44 +33,44 @@ const SpotifyMiddleware = (function(){
|
||||
var playlist = state.ui.playlist
|
||||
|
||||
if( !store.getState().spotify.authorized ){
|
||||
alert('Must be logged in to Spotify to do this')
|
||||
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
|
||||
return
|
||||
}
|
||||
if( !store.getState().spotify.me || store.getState().spotify.me.id != playlist.owner.id ){
|
||||
alert('You can only modify playlists you own')
|
||||
store.dispatch( uiActions.createNotification( "You can't edit a playlist you don't own", 'bad' ) )
|
||||
return
|
||||
}
|
||||
store.dispatch( actions.deleteTracksFromPlaylist( playlist.uri, playlist.snapshot_id, action.tracks_indexes ))
|
||||
store.dispatch( spotifyActions.deleteTracksFromPlaylist( playlist.uri, playlist.snapshot_id, action.tracks_indexes ))
|
||||
break
|
||||
|
||||
|
||||
case 'SPOTIFY_ADD_PLAYLIST_TRACKS':
|
||||
|
||||
if( !store.getState().spotify.authorized ){
|
||||
alert('Must be logged in to Spotify to do this')
|
||||
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
|
||||
return
|
||||
}
|
||||
store.dispatch( actions.addTracksToPlaylist( action.playlist_uri, action.tracks_uris ))
|
||||
store.dispatch( spotifyActions.addTracksToPlaylist( action.playlist_uri, action.tracks_uris ))
|
||||
break
|
||||
|
||||
|
||||
case 'SPOTIFY_REORDER_PLAYLIST_TRACKS':
|
||||
|
||||
if( !store.getState().spotify.authorized ){
|
||||
alert('Must be logged in to Spotify to do this')
|
||||
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
|
||||
return
|
||||
}
|
||||
store.dispatch( actions.reorderPlaylistTracks( action.uri, action.range_start, action.range_length, action.insert_before, action.snapshot_id ))
|
||||
store.dispatch( spotifyActions.reorderPlaylistTracks( action.uri, action.range_start, action.range_length, action.insert_before, action.snapshot_id ))
|
||||
break
|
||||
|
||||
|
||||
case 'SPOTIFY_SAVE_PLAYLIST':
|
||||
|
||||
if( !store.getState().spotify.authorized ){
|
||||
alert('Must be logged in to Spotify to do this')
|
||||
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
|
||||
return
|
||||
}
|
||||
store.dispatch( actions.savePlaylist( action.uri, action.name, action.is_public ))
|
||||
store.dispatch( spotifyActions.savePlaylist( action.uri, action.name, action.is_public ))
|
||||
break
|
||||
|
||||
// when our mopidy server current track changes
|
||||
@ -79,7 +81,7 @@ const SpotifyMiddleware = (function(){
|
||||
|
||||
// if the current track is a spotify track
|
||||
if( action.data && action.data.track.uri.substring(0,14) == 'spotify:track:' ){
|
||||
store.dispatch( actions.getTrack( action.data.track.uri ) )
|
||||
store.dispatch( spotifyActions.getTrack( action.data.track.uri ) )
|
||||
}
|
||||
|
||||
// This action is irrelevant to us, pass it on to the next middleware
|
||||
|
||||
Reference in New Issue
Block a user