inLibrary() instead of is_following for all library items - need to handle initial loads
This commit is contained in:
@ -487,10 +487,11 @@ export function following(uri, method = 'GET'){
|
||||
.then( response => {
|
||||
if( response ) is_following = response
|
||||
if( typeof(is_following) === 'object' ) is_following = is_following[0]
|
||||
|
||||
dispatch({
|
||||
type: 'SPOTIFY_'+asset_name.toUpperCase()+'_FOLLOWING_LOADED',
|
||||
type: asset_name.toUpperCase()+'_LIBRARY_CHECK',
|
||||
key: uri,
|
||||
is_following: is_following
|
||||
in_library: is_following
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -98,46 +98,6 @@ const SpotifyMiddleware = (function(){
|
||||
}
|
||||
break
|
||||
|
||||
case 'SPOTIFY_PLAYLIST_FOLLOWING_LOADED':
|
||||
store.dispatch({
|
||||
type: 'PLAYLIST_LOADED',
|
||||
key: action.key,
|
||||
playlist: {
|
||||
is_following: action.is_following
|
||||
}
|
||||
});
|
||||
break
|
||||
|
||||
case 'SPOTIFY_ALBUM_FOLLOWING_LOADED':
|
||||
store.dispatch({
|
||||
type: 'ALBUM_LOADED',
|
||||
key: action.key,
|
||||
album: {
|
||||
is_following: action.is_following
|
||||
}
|
||||
});
|
||||
break
|
||||
|
||||
case 'SPOTIFY_ARTIST_FOLLOWING_LOADED':
|
||||
store.dispatch({
|
||||
type: 'ARTIST_LOADED',
|
||||
key: action.key,
|
||||
artist: {
|
||||
is_following: action.is_following
|
||||
}
|
||||
});
|
||||
break
|
||||
|
||||
case 'SPOTIFY_USER_FOLLOWING_LOADED':
|
||||
store.dispatch({
|
||||
type: 'USER_LOADED',
|
||||
key: action.key,
|
||||
user: {
|
||||
is_following: action.is_following
|
||||
}
|
||||
});
|
||||
break
|
||||
|
||||
case 'SPOTIFY_NEW_RELEASES_LOADED':
|
||||
store.dispatch({
|
||||
type: 'ALBUMS_LOADED',
|
||||
@ -237,6 +197,7 @@ const SpotifyMiddleware = (function(){
|
||||
action.playlists[i],
|
||||
{
|
||||
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
|
||||
}
|
||||
@ -260,13 +221,25 @@ const SpotifyMiddleware = (function(){
|
||||
break
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ARTISTS_LOADED':
|
||||
var artists = []
|
||||
for (var i = 0; i < action.data.artists.items.length; i++){
|
||||
artists.push(
|
||||
Object.assign(
|
||||
{},
|
||||
action.data.artists.items[i],
|
||||
{
|
||||
in_library: true // assumed because we asked for library items
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
store.dispatch({
|
||||
type: 'ARTISTS_LOADED',
|
||||
artists: action.data.artists.items
|
||||
artists: artists
|
||||
});
|
||||
store.dispatch({
|
||||
type: 'LIBRARY_ARTISTS_LOADED',
|
||||
uris: helpers.asURIs(action.data.artists.items),
|
||||
uris: helpers.asURIs(artists),
|
||||
more: action.data.artists.next,
|
||||
total: action.data.artists.total
|
||||
});
|
||||
@ -280,6 +253,7 @@ const SpotifyMiddleware = (function(){
|
||||
{},
|
||||
action.data.items[i].album,
|
||||
{
|
||||
in_library: true, // assumed because we asked for library items
|
||||
added_at: action.data.items[i].added_at,
|
||||
tracks: action.data.items[i].album.tracks.items,
|
||||
tracks_more: action.data.items[i].album.tracks.next,
|
||||
|
||||
@ -258,6 +258,21 @@ export default function reducer(ui = {}, action){
|
||||
library_albums_total: action.total
|
||||
});
|
||||
|
||||
case 'ALBUM_LIBRARY_CHECK':
|
||||
var items = Object.assign([], ui.library_albums)
|
||||
|
||||
// add/remove library reference
|
||||
var index = items.indexOf(action.key)
|
||||
|
||||
// removing existing
|
||||
if (index > -1 && !action.in_library){
|
||||
items.splice(index, 1)
|
||||
} else if (index < 0 && action.in_library){
|
||||
items.push(action.key)
|
||||
}
|
||||
|
||||
return Object.assign({}, ui, { library_albums: items });
|
||||
|
||||
case 'LOCAL_ALBUMS_LOADED':
|
||||
if (!action.uris) return Object.assign({}, ui, { local_albums: null });
|
||||
return Object.assign({}, ui, { local_albums: action.uris });
|
||||
@ -349,6 +364,21 @@ export default function reducer(ui = {}, action){
|
||||
library_artists_total: action.total
|
||||
});
|
||||
|
||||
case 'ARTIST_LIBRARY_CHECK':
|
||||
var items = Object.assign([], ui.library_artists)
|
||||
|
||||
// add/remove library reference
|
||||
var index = items.indexOf(action.key)
|
||||
|
||||
// removing existing
|
||||
if (index > -1 && !action.in_library){
|
||||
items.splice(index, 1)
|
||||
} else if (index < 0 && action.in_library){
|
||||
items.push(action.key)
|
||||
}
|
||||
|
||||
return Object.assign({}, ui, { library_artists: items });
|
||||
|
||||
case 'LOCAL_ARTISTS_LOADED':
|
||||
if (!action.uris) return Object.assign({}, ui, { local_artists: null });
|
||||
return Object.assign({}, ui, { local_artists: action.uris });
|
||||
@ -511,13 +541,6 @@ export default function reducer(ui = {}, action){
|
||||
playlists[action.key] = playlist
|
||||
return Object.assign({}, ui, { playlists: playlists });
|
||||
|
||||
case 'PLAYLIST_FOLLOWING_LOADED':
|
||||
var playlists = Object.assign([], ui.playlists)
|
||||
var playlist = Object.assign({}, playlists[action.key], { following: action.is_following })
|
||||
|
||||
playlists[action.key] = playlist
|
||||
return Object.assign({}, ui, { playlists: playlists });
|
||||
|
||||
case 'LIBRARY_PLAYLISTS_LOADED':
|
||||
if (ui.library_playlists){
|
||||
var library_playlists = [...ui.library_playlists, ...action.uris]
|
||||
@ -531,6 +554,21 @@ export default function reducer(ui = {}, action){
|
||||
library_playlists: library_playlists
|
||||
});
|
||||
|
||||
case 'PLAYLIST_LIBRARY_CHECK':
|
||||
var items = Object.assign([], ui.library_playlists)
|
||||
|
||||
// add/remove library reference
|
||||
var index = items.indexOf(action.key)
|
||||
|
||||
// removing existing
|
||||
if (index > -1 && !action.in_library){
|
||||
items.splice(index, 1)
|
||||
} else if (index < 0 && action.in_library){
|
||||
items.push(action.key)
|
||||
}
|
||||
|
||||
return Object.assign({}, ui, { library_playlists: items });
|
||||
|
||||
|
||||
/**
|
||||
* Search results
|
||||
|
||||
Reference in New Issue
Block a user