Resolving radio seeds

This commit is contained in:
James Barnsley
2017-01-08 13:32:46 +13:00
parent 1887dfc364
commit deb1340141
5 changed files with 71 additions and 5 deletions

View File

@ -412,6 +412,45 @@ export function following(uri, method = 'GET'){
}
}
/**
* Resolve radio seeds into full objects
*
* @param radio object
**/
export function resolveRadioSeeds( radio ){
return (dispatch, getState) => {
// flush out the previous store value
dispatch({ type: 'PUSHER_RADIO_SEEDS_RESOLVING' });
var resolved_seeds = {
seed_artists: [],
seed_tracks: [],
seed_genres: []
}
var artist_ids = '';
for (var i = 0; i < radio.seed_artists.length; i++){
if (i > 0) artist_ids += ','
artist_ids += helpers.getFromUri('artistid', radio.seed_artists[i])
}
$.when(
sendRequest( dispatch, getState, 'artists/'+ artist_ids )
.then( response => {
if (!(response instanceof Array)) response = [response]
Object.assign(resolved_seeds.seed_artists, response);
})
).then( () => {
dispatch({
type: 'PUSHER_RADIO_SEEDS_RESOLVED',
data: resolved_seeds
});
});
}
}
/**
* =============================================================== ARTIST(S) ============