Adding play artist top tracks, fixes #32

This commit is contained in:
James Barnsley
2017-07-17 04:19:02 +12:00
parent bd1246d0b6
commit 1889186bed
3 changed files with 37 additions and 1 deletions

View File

@ -1,5 +1,6 @@
var uiActions = require('../../services/ui/actions')
var mopidyActions = require('../../services/mopidy/actions')
var lastfmActions = require('../../services/lastfm/actions')
var helpers = require('../../helpers')
@ -912,6 +913,27 @@ export function getLibraryArtists(){
}
export function playArtistTopTracks(uri){
return (dispatch, getState) => {
const artists = getState().ui.artists
// Do we have this artist (and their tracks) in our index already?
if (typeof(artists[uri]) !== 'undefined' && typeof(artists[uri].tracks) !== 'undefined'){
const uris = helpers.asURIs(artists[uri].tracks)
dispatch(mopidyActions.playURIs(uris, uri))
// We need to load the artist's top tracks first
} else {
sendRequest( dispatch, getState, 'artists/'+ helpers.getFromUri('artistid', uri) +'/top-tracks?country='+getState().spotify.country )
.then( response => {
const uris = helpers.asURIs(response.tracks)
dispatch(mopidyActions.playURIs(uris, uri))
})
}
}
}
/**
* =============================================================== USER(S) ==============