import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' 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 ArtistList from '../components/ArtistList' import ArtistGrid from '../components/ArtistGrid' import FollowButton from '../components/FollowButton' import SidebarToggleButton from '../components/SidebarToggleButton' import * as helpers from '../helpers' import * as mopidyActions from '../services/mopidy/actions' import * as lastfmActions from '../services/lastfm/actions' import * as spotifyActions from '../services/spotify/actions' class Artist extends React.Component{ constructor(props) { super(props) this.state = { sub_view: 'overview' } } 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 ) == 'local' ){ this.loadArtist( nextProps ) } } } componentWillUpdate( nextProps, nextState ){ if( nextState.sub_view != this.state.sub_view && nextState.sub_view == 'biography' ){ if( this.props.artist && !this.props.artist.bio ){ this.props.lastfmActions.getArtist( this.props.artist.name.replace('&','and') ) } } } loadArtist( props = this.props ){ var source = helpers.uriSource( props.params.uri ); if( source == 'spotify' ){ this.props.spotifyActions.getArtist( props.params.uri ); }else if( source == 'local' && props.mopidy_connected ){ this.props.mopidyActions.getArtist( props.params.uri ); } } loadMore(){ if( !this.props.artist.albums_more ) return this.props.spotifyActions.getURL( this.props.artist.albums_more, 'SPOTIFY_ARTIST_ALBUMS_LOADED_MORE' ); } play(){ alert('Yet to be implemented') } renderSubViewMenu(){ return (
this.setState({ sub_view: 'overview' })}> Overview this.setState({ sub_view: 'related_artists' })}> Related artists this.setState({ sub_view: 'biography' })}> Biography
) } renderBody(){ if( this.state.sub_view == 'related_artists' ){ return (

Related artists

{ this.props.artist.related_artists ? : null }
) }else if( this.state.sub_view == 'biography' ){ return (

Biography

{ 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 body return (

Top tracks

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

Related artists

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

Albums

{ this.props.artist.albums ? : null } this.loadMore() }/>
) } render(){ if( !this.props.artist ) return null var scheme = helpers.uriSource( this.props.params.uri ); var images = [] if( this.props.artist.images ) images = this.props.artist.images return (

{ this.props.artist.name }

{ this.renderSubViewMenu() }
{ helpers.uriSource(this.props.params.uri) == 'spotify' ? : null }
  • { this.props.artist.followers ? { this.props.artist.followers.total.toLocaleString() } followers,  : null } { this.props.artist.popularity ? { this.props.artist.popularity }% popularity : null } { scheme == 'local' ? { this.props.artist.listeners.toLocaleString() } listeners : null }
  • { scheme == 'spotify' ?
  • Spotify artist
  • : null } { scheme == 'local' ?
  • Local artist
  • : null }
{ this.renderBody() }
); } } /** * Export our component * * We also integrate our global store, using connect() **/ const mapStateToProps = (state, ownProps) => { return { artist: state.ui.artist, spotify_authorized: state.spotify.authorized, mopidy_connected: state.mopidy.connected } } const mapDispatchToProps = (dispatch) => { return { mopidyActions: bindActionCreators(mopidyActions, dispatch), lastfmActions: bindActionCreators(lastfmActions, dispatch), spotifyActions: bindActionCreators(spotifyActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(Artist)