import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' let helpers = require('../helpers.js') 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 * as mopidyActions from '../services/mopidy/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 ) == 'local' ){ this.loadArtist( nextProps ) } } } 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.spotify.artist_albums || !this.props.spotify.artist_albums.next ) return this.props.spotifyActions.getURL( this.props.spotify.artist_albums.next, 'SPOTIFY_ARTIST_ALBUMS_LOADED_MORE' ); } renderSpotifyAlbum(){ if( !this.props.spotify.artist ) return null var artist = this.props.spotify.artist var albums = this.props.spotify.artist_albums return (

{ artist.name }

{ artist.followers.total.toLocaleString() } followers

Top tracks

{ artist.tracks ? : null }

Related artists

{ artist.related_artists ? : null }

Albums

{ albums ? : null } this.loadMore() }/>
); } renderMopidyAlbum(){ if( !this.props.mopidy.artist ) return null var artist = this.props.mopidy.artist return (

{ artist.name }

Top tracks

{ artist.tracks ? : null }

Albums

{ artist.albums ? : null }
); } render(){ var source = helpers.uriSource( this.props.params.uri ); if( source == 'spotify' ) return this.renderSpotifyAlbum() if( source == 'local' ) return this.renderMopidyAlbum() } } /** * Export our component * * We also integrate our global store, using connect() **/ const mapStateToProps = (state, ownProps) => { return state; } const mapDispatchToProps = (dispatch) => { return { mopidyActions: bindActionCreators(mopidyActions, dispatch), spotifyActions: bindActionCreators(spotifyActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(Artist)