Ignore duplicate albums; Don't search when no seeds

This commit is contained in:
James Barnsley
2017-05-16 12:05:20 +12:00
parent ea85f2b18d
commit bd455aa232
2 changed files with 11 additions and 7 deletions

View File

@ -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)
}
}
}

View File

@ -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)
}