Lazy loading keys; Spotify new releases in Spotify reducer, handling duplicates bug

This commit is contained in:
James Barnsley
2018-09-03 14:22:27 +12:00
parent 3344cf5db4
commit 93be7e096b
11 changed files with 14015 additions and 10771 deletions

View File

@ -158,27 +158,6 @@ export default function reducer(core = {}, action){
return Object.assign({}, core, { users: users });
case 'NEW_RELEASES_LOADED':
if (!action.uris){
return Object.assign({}, core, {
new_releases: null,
new_releases_more: null,
new_releases_total: null
});
}
var new_releases = [];
if (core.new_releases){
new_releases = Object.assign([], core.new_releases);
}
return Object.assign({}, core, {
new_releases: [...new_releases, ...action.uris],
new_releases_more: action.more,
new_releases_total: action.total
});
case 'ARTIST_ALBUMS_LOADED':
var artists = Object.assign({}, core.artists)
var albums_uris = [];

View File

@ -106,12 +106,14 @@ const SpotifyMiddleware = (function(){
type: 'ALBUMS_LOADED',
albums: action.data.albums.items
});
store.dispatch({
type: 'NEW_RELEASES_LOADED',
uris: helpers.arrayOf('uri',action.data.albums.items),
more: action.data.albums.next,
total: action.data.albums.total
});
// Collate result into the three key values we want
action.uris = helpers.arrayOf('uri', action.data.albums.items);
action.more = action.data.albums.next;
action.total = action.data.albums.total;
// And pass on to our reducer
next(action);
break
case 'SPOTIFY_ARTIST_ALBUMS_LOADED':

View File

@ -68,17 +68,17 @@ export default function reducer(spotify = {}, action){
case 'SPOTIFY_FEATURED_PLAYLISTS_LOADED':
return Object.assign({}, spotify, { featured_playlists: action.data })
case 'SPOTIFY_NEW_RELEASES_LOADED':
return Object.assign({}, spotify, { new_releases: action.data });
case 'SPOTIFY_NEW_RELEASES_LOADED_MORE':
console.log([ ...spotify.new_releases.items, ...action.data.albums.items]);
return Object.assign({}, spotify, { new_releases: {
href: action.data.albums.href,
next: action.data.albums.next,
previous: action.data.albums.previous,
items: [ ...spotify.new_releases.items, ...action.data.albums.items]
}});
case 'SPOTIFY_NEW_RELEASES_LOADED':
var new_releases = [];
if (spotify.new_releases){
new_releases = Object.assign([], spotify.new_releases);
}
return Object.assign({}, spotify, {
new_releases: helpers.removeDuplicates([...new_releases, ...action.uris]),
new_releases_more: action.more,
new_releases_total: action.total
});
case 'SPOTIFY_DISCOVER_LOADED':
if (!action.data ){