Artwork for local artists; Hide related when empty
This commit is contained in:
@ -607,49 +607,51 @@ const MopidyMiddleware = (function(){
|
||||
|
||||
case 'MOPIDY_GET_ARTIST':
|
||||
instruct( socket, store, 'library.lookup', action.data )
|
||||
.then( response => {
|
||||
.then( response => {
|
||||
|
||||
var albums = []
|
||||
for( var i = 0; i < response.length; i++ ){
|
||||
var album = response[i].album;
|
||||
|
||||
function getByURI( albumToCheck ){
|
||||
return album.uri == albumToCheck.uri
|
||||
}
|
||||
var existingAlbum = albums.find(getByURI);
|
||||
if( !existingAlbum ){
|
||||
albums.push(album)
|
||||
if (album){
|
||||
function getByURI( albumToCheck ){
|
||||
return album.uri == albumToCheck.uri
|
||||
}
|
||||
var existingAlbum = albums.find(getByURI);
|
||||
if( !existingAlbum ){
|
||||
albums.push(album)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
store.dispatch({
|
||||
type: 'ALBUMS_LOADED',
|
||||
albums: albums
|
||||
})
|
||||
if (albums){
|
||||
store.dispatch({
|
||||
type: 'ALBUMS_LOADED',
|
||||
albums: albums
|
||||
})
|
||||
}
|
||||
|
||||
var artist = Object.assign(
|
||||
{},
|
||||
response[0].artists[0],
|
||||
{
|
||||
images: [],
|
||||
albums_uris: helpers.asURIs(albums),
|
||||
tracks: response.slice(0,10)
|
||||
}
|
||||
)
|
||||
|
||||
// load artwork from LastFM
|
||||
if( artist.images.length <= 0 ){
|
||||
if( artist.musicbrainz_id ){
|
||||
store.dispatch( lastfmActions.getArtist( artist.uri, false, artist.musicbrainz_id ) )
|
||||
}else{
|
||||
store.dispatch( lastfmActions.getArtist( artist.uri, artist.name.replace('&','and') ) )
|
||||
}
|
||||
}
|
||||
|
||||
store.dispatch({
|
||||
type: 'ARTIST_LOADED',
|
||||
uri: artist.uri,
|
||||
artist: artist
|
||||
});
|
||||
|
||||
// load artwork from LastFM
|
||||
if( !artist.images || artist.images.length <= 0 ){
|
||||
if( artist.musicbrainz_id ){
|
||||
store.dispatch( lastfmActions.getArtist( artist.uri, false, artist.musicbrainz_id ) )
|
||||
}else{
|
||||
store.dispatch( lastfmActions.getArtist( artist.uri, artist.name.replace('&','and') ) )
|
||||
}
|
||||
}
|
||||
})
|
||||
break;
|
||||
|
||||
|
||||
@ -129,19 +129,6 @@ export default function reducer(ui = {}, action){
|
||||
* Albums
|
||||
**/
|
||||
|
||||
case 'ALBUMS_LOADED':
|
||||
var albums = Object.assign([], ui.albums)
|
||||
|
||||
for (var i = 0; i < action.albums.length; i++){
|
||||
var album = action.albums[i]
|
||||
if (typeof(albums[album.uri]) !== 'undefined'){
|
||||
artist = Object.assign({}, albums[album.uri], album)
|
||||
}
|
||||
albums[album.uri] = album
|
||||
}
|
||||
|
||||
return Object.assign({}, ui, { albums: albums });
|
||||
|
||||
case 'ALBUM_LOADED':
|
||||
var albums = Object.assign([], ui.albums)
|
||||
|
||||
@ -154,6 +141,20 @@ export default function reducer(ui = {}, action){
|
||||
albums[action.uri] = album
|
||||
return Object.assign({}, ui, { albums: albums });
|
||||
|
||||
case 'ALBUMS_LOADED':
|
||||
console.log(action)
|
||||
var albums = Object.assign([], ui.albums)
|
||||
|
||||
for (var i = 0; i < action.albums.length; i++){
|
||||
var album = action.albums[i]
|
||||
if (typeof(albums[album.uri]) !== 'undefined'){
|
||||
artist = Object.assign({}, albums[album.uri], album)
|
||||
}
|
||||
albums[album.uri] = album
|
||||
}
|
||||
|
||||
return Object.assign({}, ui, { albums: albums });
|
||||
|
||||
case 'LIBRARY_ALBUMS_LOADED':
|
||||
if (!action.uris){
|
||||
return Object.assign({}, ui, {
|
||||
@ -200,6 +201,22 @@ export default function reducer(ui = {}, action){
|
||||
* Artists
|
||||
**/
|
||||
|
||||
case 'ARTIST_LOADED':
|
||||
console.log(action)
|
||||
var artists = Object.assign([], ui.artists)
|
||||
|
||||
if (artists[action.uri]){
|
||||
// if we've already got images, delete our new ones
|
||||
// this is to prevent LastFM overwriting Spotify images
|
||||
if (artists[action.uri].images) delete action.artist.images
|
||||
var artist = Object.assign({}, artists[action.uri], action.artist)
|
||||
}else{
|
||||
var artist = Object.assign({}, action.artist)
|
||||
}
|
||||
|
||||
artists[action.uri] = artist
|
||||
return Object.assign({}, ui, { artists: artists });
|
||||
|
||||
case 'ARTISTS_LOADED':
|
||||
var artists = Object.assign([], ui.artists)
|
||||
|
||||
@ -213,18 +230,6 @@ export default function reducer(ui = {}, action){
|
||||
|
||||
return Object.assign({}, ui, { artists: artists });
|
||||
|
||||
case 'ARTIST_LOADED':
|
||||
var artists = Object.assign([], ui.artists)
|
||||
|
||||
if (artists[action.uri]){
|
||||
var artist = Object.assign({}, artists[action.uri], action.artist)
|
||||
}else{
|
||||
var artist = Object.assign({}, action.artist)
|
||||
}
|
||||
|
||||
artists[action.uri] = artist
|
||||
return Object.assign({}, ui, { artists: artists });
|
||||
|
||||
case 'ARTIST_ALBUMS_LOADED':
|
||||
var artists = Object.assign([], ui.artists)
|
||||
var albums_uris = []
|
||||
@ -242,18 +247,6 @@ export default function reducer(ui = {}, action){
|
||||
artists[action.uri] = artist
|
||||
return Object.assign({}, ui, { artists: artists });
|
||||
|
||||
/*
|
||||
case 'LASTFM_ARTIST_LOADED':
|
||||
if( !action.data.image ) return ui
|
||||
|
||||
// if we already have images, don't overwrite them
|
||||
var images = ui.artist.images
|
||||
if( images.length <= 0 ) images = action.data.image
|
||||
|
||||
var artist = Object.assign({}, ui.artist, { images: images, bio: action.data.bio, listeners: parseInt(action.data.stats.listeners), on_tour: action.data.ontour }, )
|
||||
return Object.assign({}, ui, { artist: artist });
|
||||
*/
|
||||
|
||||
case 'LIBRARY_ARTISTS_LOADED':
|
||||
if (!action.uris){
|
||||
return Object.assign({}, ui, {
|
||||
|
||||
@ -150,14 +150,14 @@ class Artist extends React.Component{
|
||||
|
||||
return (
|
||||
<div className="body overview">
|
||||
<div className={this.props.artist.related_artists ? "col w70" : "col w100"}>
|
||||
<div className={related_artists.length > 0 ? "col w70" : "col w100"}>
|
||||
<h4 className="left-padding">Top tracks</h4>
|
||||
{ this.props.artist.tracks ? <TrackList tracks={ this.props.artist.tracks } /> : null }
|
||||
</div>
|
||||
|
||||
<div className="col w5"></div>
|
||||
|
||||
{this.props.artist.related_artists ? <div className="col w25 related-artists"><h4>Related artists</h4><ArtistList artists={related_artists.slice(0,6)} /></div> : null}
|
||||
{related_artists.length > 0 ? <div className="col w25 related-artists"><h4>Related artists</h4><ArtistList artists={related_artists.slice(0,6)} /></div> : null}
|
||||
|
||||
<div className="cf"></div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user