diff --git a/src/js/components/ContextMenu.js b/src/js/components/ContextMenu.js index e351e4dd..94327e14 100755 --- a/src/js/components/ContextMenu.js +++ b/src/js/components/ContextMenu.js @@ -174,6 +174,11 @@ class ContextMenu extends React.Component{ this.props.mopidyActions.playPlaylist(this.props.menu.uris[0]) } + playArtistTopTracks(e){ + this.props.uiActions.hideContextMenu() + this.props.spotifyActions.playArtistTopTracks(this.props.menu.uris[0]) + } + addToQueue(e, next = false){ this.props.uiActions.hideContextMenu() this.props.mopidyActions.enqueueURIs(this.props.menu.uris, this.props.menu.tracklist_uri, next) @@ -361,6 +366,14 @@ class ContextMenu extends React.Component{ ) + var play_artist_top_tracks = ( + + this.playArtistTopTracks(e)}> + Play top tracks + + + ) + var add_to_queue = ( this.addToQueue(e)}> @@ -463,6 +476,7 @@ class ContextMenu extends React.Component{ case 'artist': return (
+ {context.source == 'spotify' ? play_artist_top_tracks : null} {start_radio} {context.source == 'spotify' ? go_to_recommendations : null} {copy_uris} diff --git a/src/js/services/spotify/actions.js b/src/js/services/spotify/actions.js index d03e1766..9a0faf5c 100755 --- a/src/js/services/spotify/actions.js +++ b/src/js/services/spotify/actions.js @@ -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) ============== diff --git a/src/js/views/Artist.js b/src/js/views/Artist.js index 021feef7..7fe5a828 100755 --- a/src/js/views/Artist.js +++ b/src/js/views/Artist.js @@ -31,7 +31,7 @@ class Artist extends React.Component{ } componentDidMount(){ - this.loadArtist(); + this.loadArtist() } componentWillReceiveProps( nextProps ){