import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import { Link } from 'react-router' import FontAwesome from 'react-fontawesome' import LazyLoadListener from '../components/LazyLoadListener' import Header from '../components/Header' import TrackList from '../components/TrackList' import AlbumGrid from '../components/AlbumGrid' import Thumbnail from '../components/Thumbnail' import Parallax from '../components/Parallax' import ArtistGrid from '../components/ArtistGrid' import RelatedArtists from '../components/RelatedArtists' import FollowButton from '../components/FollowButton' import SidebarToggleButton from '../components/SidebarToggleButton' import ContextMenuTrigger from '../components/ContextMenuTrigger' import * as helpers from '../helpers' import * as uiActions from '../services/ui/actions' import * as mopidyActions from '../services/mopidy/actions' import * as pusherActions from '../services/pusher/actions' import * as lastfmActions from '../services/lastfm/actions' import * as spotifyActions from '../services/spotify/actions' class Artist extends React.Component{ constructor(props) { super(props) } componentDidMount(){ this.loadArtist() } componentWillReceiveProps( nextProps ){ if( nextProps.params.uri != this.props.params.uri ){ this.loadArtist( nextProps ) }else if( !this.props.mopidy_connected && nextProps.mopidy_connected ){ if( helpers.uriSource( this.props.params.uri ) != 'spotify' ){ this.loadArtist( nextProps ) } } } handleContextMenu(e){ var data = { e: e, context: 'artist', items: [this.props.artist], uris: [this.props.params.uri] } this.props.uiActions.showContextMenu(data) } loadArtist( props = this.props ){ switch( helpers.uriSource( props.params.uri ) ){ case 'spotify': if (props.artist && props.artist.albums_uris && props.artist.related_artists_uris){ console.info('Loading spotify artist from index') }else{ this.props.spotifyActions.getArtist(props.params.uri, true); } break default: if (props.mopidy_connected){ if (props.artist && props.artist.images){ console.info('Loading local artist from index') } else { this.props.mopidyActions.getArtist(props.params.uri); } } break } } loadMore(){ this.props.spotifyActions.getURL( this.props.artist.albums_more, 'SPOTIFY_ARTIST_ALBUMS_LOADED', this.props.params.uri ); } inLibrary(){ return (this.props.library_artists && this.props.library_artists.indexOf(this.props.params.uri) > -1) } renderSubViewMenu(){ return (

Overview

Related artists

About

) } renderBody(){ if (helpers.isLoading(this.props.load_queue,['spotify_artists/'+helpers.getFromUri('artistid',this.props.params.uri), 'lastfm_method=artist.getInfo'])){ return (
) } var scheme = helpers.uriSource( this.props.params.uri ); var related_artists = [] if (this.props.artist.related_artists_uris){ for (var i = 0; i < this.props.artist.related_artists_uris.length; i++){ var uri = this.props.artist.related_artists_uris[i] if (this.props.artists.hasOwnProperty(uri)){ related_artists.push(this.props.artists[uri]) } } } var albums = [] if (this.props.artist.albums_uris){ for (var i = 0; i < this.props.artist.albums_uris.length; i++){ var uri = this.props.artist.albums_uris[i] if (this.props.albums.hasOwnProperty(uri)){ albums.push(this.props.albums[uri]) } } } switch (this.props.params.sub_view){ case 'related-artists': return (
) case 'about': return (
{this.props.artist.images ?
: null} {this.props.artist.images_additional ?
: null} {this.props.artist.followers ?
{this.props.artist.followers.total.toLocaleString() } followers
: null} {this.props.artist.popularity ?
{this.props.artist.popularity }% popularity
: null} {this.props.artist.listeners ?
{ this.props.artist.listeners.toLocaleString() } listeners
: null }
{ this.props.artist.bio ?

{this.props.artist.bio.content}


Published: { this.props.artist.bio.published }
Origin: { this.props.artist.bio.links.link.href }
: null }
) default: return (
0 ? "col w70" : "col w100"}>

Top tracks

{ this.props.artist.tracks ? : null }
{related_artists.length > 0 ?

Related artists

All related artists
: null}

Albums

this.loadMore() }/>
) } } render(){ var scheme = helpers.uriSource( this.props.params.uri ) if ( this.props.artist && this.props.artist.images ){ var image = helpers.sizedImages( this.props.artist.images ).huge } else { var image = null } if (this.props.artist){ var can_play_radio = (scheme == 'spotify') var can_follow = (scheme == 'spotify') return (
{this.props.slim_mode ?
this.handleContextMenu(e)} uiActions={this.props.uiActions} /> : null}

{this.props.artist ? this.props.artist.name : null}

{ can_play_radio ? : } { can_follow ? : null} {this.props.slim_mode ? null : this.handleContextMenu(e)} />}
{ this.renderSubViewMenu() }
{this.renderBody()}
); } else { return (

{ this.renderSubViewMenu() }
{this.renderBody()}
); } } } /** * Export our component * * We also integrate our global store, using connect() **/ const mapStateToProps = (state, ownProps) => { return { slim_mode: state.ui.slim_mode, load_queue: state.ui.load_queue, artist: (state.ui.artists && typeof(state.ui.artists[ownProps.params.uri]) !== 'undefined' ? state.ui.artists[ownProps.params.uri] : false ), artists: (state.ui.artists ? state.ui.artists : []), library_artists: (state.ui.library_artists ? state.ui.library_artists : []), albums: (state.ui.albums ? state.ui.albums : []), spotify_authorized: state.spotify.authorized, mopidy_connected: state.mopidy.connected } } const mapDispatchToProps = (dispatch) => { return { uiActions: bindActionCreators(uiActions, dispatch), mopidyActions: bindActionCreators(mopidyActions, dispatch), pusherActions: bindActionCreators(pusherActions, dispatch), lastfmActions: bindActionCreators(lastfmActions, dispatch), spotifyActions: bindActionCreators(spotifyActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(Artist)