Moving can_edit on playlists to ui middleware, fixes #73

This commit is contained in:
James Barnsley
2017-03-20 18:20:59 +13:00
parent 423c5ae91f
commit 98e4e2db54
4 changed files with 28 additions and 5 deletions

View File

@ -186,6 +186,12 @@ export let getFromUri = function(element,uri){
}
break
case 'playlistowner':
if (exploded[1] == 'user' && exploded[3] == 'playlist'){
return exploded[2]
}
break
case 'trackid':
if (exploded[1] == 'track'){
return exploded[2]

View File

@ -353,7 +353,6 @@ const MopidyMiddleware = (function(){
uri: response.uri,
source: (source == 'spotify' ? 'local' : source),
last_modified: response.last_modified,
can_edit: (response.uri.startsWith('m3u:')),
tracks_total: ( response.tracks ? response.tracks.length : 0 )
}
)

View File

@ -132,7 +132,6 @@ const SpotifyMiddleware = (function(){
{},
action.data.items[i],
{
can_edit: (store.getState().spotify.authorized && store.getState().spotify.me && action.data.items[i].owner.id == store.getState().spotify.me.id),
tracks_total: action.data.items[i].tracks.total
}
)
@ -164,7 +163,6 @@ const SpotifyMiddleware = (function(){
{},
action.data.playlists.items[i],
{
can_edit: (store.getState().spotify.authorized && store.getState().spotify.me && action.data.playlists.items[i].owner.id == store.getState().spotify.me.id),
tracks_total: action.data.playlists.items[i].tracks.total
}
)
@ -198,7 +196,6 @@ const SpotifyMiddleware = (function(){
{
source: 'spotify',
in_library: true, // assumed because we asked for library items
can_edit: (store.getState().spotify.authorized && store.getState().spotify.me && action.playlists[i].owner.id == store.getState().spotify.me.id),
tracks_total: action.playlists[i].tracks.total
}
)
@ -320,7 +317,6 @@ const SpotifyMiddleware = (function(){
{},
action.data.playlists.items[i],
{
can_edit: (getState().spotify.me && action.data.playlists.items[i].owner.id == getState().spotify.me.id),
tracks_total: action.data.playlists.items[i].tracks.total
}
))

View File

@ -198,6 +198,28 @@ const UIMiddleware = (function(){
next(action)
break
case 'PLAYLIST_LOADED':
var playlist = action.playlist
switch (helpers.uriSource(playlist.uri)){
case 'm3u':
playlist.can_edit = true
break
case 'spotify':
if (store.getState().spotify.authorized && store.getState().spotify.me){
playlist.can_edit = (helpers.getFromUri('playlistowner',playlist.uri) == store.getState().spotify.me.id)
} else {
console.log('nah')
}
}
// proceed as usual
action.playlist = playlist
next(action)
break
case 'MOPIDY_STATE':
helpers.setWindowTitle(store.getState().ui.current_track, action.data)