diff --git a/src/js/services/spotify/actions.js b/src/js/services/spotify/actions.js index 58151eb4..f21f6fd7 100755 --- a/src/js/services/spotify/actions.js +++ b/src/js/services/spotify/actions.js @@ -718,10 +718,17 @@ export function getRecommendations(uris = [], limit = 20){ // Copy already loaded albums into array var albums = [] + var albums_uris = [] if (response.tracks.length > 10){ - for (var i = 0; i < 5; i++){ + while (albums.length < 5){ var random_index = Math.round(Math.random() * (response.tracks.length - 1)) - albums.push(response.tracks[random_index].album) + var album = response.tracks[random_index].album + + // Make sure this album is not already in our sample + if (!albums_uris.includes(album.uri)){ + albums_uris.push(album.uri) + albums.push(album) + } } } diff --git a/src/js/views/discover/Discover.js b/src/js/views/discover/Discover.js index 905eeac8..81051a93 100755 --- a/src/js/views/discover/Discover.js +++ b/src/js/views/discover/Discover.js @@ -30,10 +30,7 @@ class Discover extends React.Component{ } ], add_seed: '', - adding_seed: false, - artists: [], - albums: [], - tracks: [] + adding_seed: false } } @@ -60,7 +57,7 @@ class Discover extends React.Component{ } getRecommendations(seeds = this.state.seeds){ - if (seeds){ + if (seeds.length > 0){ var uris = helpers.asURIs(seeds) this.props.spotifyActions.getRecommendations(uris, 50) }