From 1a5523503f4e4ffe815ef746735dbbee5a39396f Mon Sep 17 00:00:00 2001 From: James Barnsley Date: Fri, 10 Mar 2017 09:04:42 +1300 Subject: [PATCH] _library_started switch to indicate whether we've started loading --- src/js/services/ui/reducer.js | 29 +++++++------------------- src/js/views/App.js | 5 +++-- src/js/views/library/LibraryAlbums.js | 5 ++++- src/js/views/library/LibraryArtists.js | 5 ++++- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/js/services/ui/reducer.js b/src/js/services/ui/reducer.js index 4bc8595d..bc43e9aa 100755 --- a/src/js/services/ui/reducer.js +++ b/src/js/services/ui/reducer.js @@ -241,21 +241,14 @@ export default function reducer(ui = {}, action){ return Object.assign({}, ui, { albums: albums }); case 'LIBRARY_ALBUMS_LOADED': - if (!action.uris){ - return Object.assign({}, ui, { - library_albums: null, - library_albums_more: null, - library_albums_total: null - }); - } - var library_albums = [] if (ui.library_albums) library_albums = Object.assign([], ui.library_albums) return Object.assign({}, ui, { - library_albums: [...library_albums, ...action.uris], + library_albums: helpers.removeDuplicates([...library_albums, ...action.uris]), library_albums_more: action.more, - library_albums_total: action.total + library_albums_total: action.total, + library_albums_started: true }); case 'ALBUM_LIBRARY_CHECK': @@ -347,21 +340,14 @@ export default function reducer(ui = {}, action){ return Object.assign({}, ui, { artists: artists }); case 'LIBRARY_ARTISTS_LOADED': - if (!action.uris){ - return Object.assign({}, ui, { - library_artists: null, - library_artists_more: null, - library_artists_total: null - }); - } - var library_artists = [] if (ui.library_artists) library_artists = Object.assign([], ui.library_artists) return Object.assign({}, ui, { - library_artists: [...library_artists, ...action.uris], + library_artists: helpers.removeDuplicates([...library_artists, ...action.uris]), library_artists_more: action.more, - library_artists_total: action.total + library_artists_total: action.total, + library_artists_started: true }); case 'ARTIST_LIBRARY_CHECK': @@ -551,7 +537,8 @@ export default function reducer(ui = {}, action){ library_playlists = helpers.removeDuplicates(library_playlists) return Object.assign({}, ui, { - library_playlists: library_playlists + library_playlists: library_playlists, + library_playlists_loaded: true }); case 'PLAYLIST_LIBRARY_CHECK': diff --git a/src/js/views/App.js b/src/js/views/App.js index cc484b4f..72d931d5 100755 --- a/src/js/views/App.js +++ b/src/js/views/App.js @@ -43,9 +43,10 @@ class App extends React.Component{ this.props.spotifyActions.connect(); if (this.props.spotify_authorized){ + + // TODO: remove this so we don't tap out our API limits before we even get started + // Perhaps fire this on demand? Context menu, playlists loading or AddToPlaylistModal this.props.spotifyActions.getAllLibraryPlaylists(); - this.props.spotifyActions.getLibraryAlbums(); - this.props.spotifyActions.getLibraryArtists(); } // when we navigate to a new route diff --git a/src/js/views/library/LibraryAlbums.js b/src/js/views/library/LibraryAlbums.js index a3c3cbe4..17eb7936 100755 --- a/src/js/views/library/LibraryAlbums.js +++ b/src/js/views/library/LibraryAlbums.js @@ -25,7 +25,9 @@ class LibraryAlbums extends React.Component{ } componentDidMount(){ - if (!this.props.library_albums) this.props.spotifyActions.getLibraryAlbums(); + if (!this.props.library_albums_started){ + this.props.spotifyActions.getLibraryAlbums(); + } } handleContextMenu(e,item){ @@ -215,6 +217,7 @@ const mapStateToProps = (state, ownProps) => { sort_reverse: state.ui.library_albums_sort_reverse, library_albums: state.ui.library_albums, library_albums_more: state.ui.library_albums_more, + library_albums_started: state.ui.library_albums_started, } } diff --git a/src/js/views/library/LibraryArtists.js b/src/js/views/library/LibraryArtists.js index b4d2ad04..207544b4 100755 --- a/src/js/views/library/LibraryArtists.js +++ b/src/js/views/library/LibraryArtists.js @@ -32,7 +32,9 @@ class LibraryArtists extends React.Component{ } componentDidMount(){ - if (!this.props.library_artists) this.props.spotifyActions.getLibraryArtists(); + if (!this.props.library_artists_started){ + this.props.spotifyActions.getLibraryArtists(); + } } loadMore(){ @@ -162,6 +164,7 @@ const mapStateToProps = (state, ownProps) => { sort_reverse: state.ui.library_artists_sort_reverse, library_artists: state.ui.library_artists, library_artists_more: state.ui.library_artists_more, + library_artists_started: state.ui.library_artists_started, view: state.ui.library_artists_view } }