2016-10-17 10:39:11 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
2016-11-07 21:21:15 +13:00
|
|
|
import FontAwesome from 'react-fontawesome'
|
2016-10-17 10:39:11 +13:00
|
|
|
|
2016-11-01 08:57:28 +13:00
|
|
|
import LazyLoadListener from '../components/LazyLoadListener'
|
2016-10-24 21:26:01 +13:00
|
|
|
import Header from '../components/Header'
|
2016-10-17 10:39:11 +13:00
|
|
|
import TrackList from '../components/TrackList'
|
2016-10-18 21:57:29 +13:00
|
|
|
import AlbumGrid from '../components/AlbumGrid'
|
2016-10-25 17:01:37 +13:00
|
|
|
import Thumbnail from '../components/Thumbnail'
|
|
|
|
|
import Parallax from '../components/Parallax'
|
2016-10-25 21:36:33 +13:00
|
|
|
import ArtistList from '../components/ArtistList'
|
2016-11-23 13:17:07 +13:00
|
|
|
import ArtistGrid from '../components/ArtistGrid'
|
2016-11-18 13:21:30 +13:00
|
|
|
import FollowButton from '../components/FollowButton'
|
2016-10-18 21:57:29 +13:00
|
|
|
|
2016-11-18 13:21:30 +13:00
|
|
|
import * as helpers from '../helpers'
|
2016-11-01 16:41:04 +13:00
|
|
|
import * as mopidyActions from '../services/mopidy/actions'
|
2016-11-07 21:21:15 +13:00
|
|
|
import * as lastfmActions from '../services/lastfm/actions'
|
2016-10-17 10:39:11 +13:00
|
|
|
import * as spotifyActions from '../services/spotify/actions'
|
|
|
|
|
|
|
|
|
|
class Artist extends React.Component{
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
2016-11-23 13:17:07 +13:00
|
|
|
super(props)
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
sub_view: 'overview'
|
|
|
|
|
}
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount(){
|
2016-11-01 16:41:04 +13:00
|
|
|
this.loadArtist();
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps( nextProps ){
|
|
|
|
|
if( nextProps.params.uri != this.props.params.uri ){
|
2016-11-01 16:41:04 +13:00
|
|
|
this.loadArtist( nextProps )
|
2016-11-09 21:13:40 +13:00
|
|
|
}else if( !this.props.mopidy_connected && nextProps.mopidy_connected ){
|
2016-11-01 16:41:04 +13:00
|
|
|
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 );
|
2016-11-09 21:13:40 +13:00
|
|
|
}else if( source == 'local' && props.mopidy_connected ){
|
2016-11-01 16:41:04 +13:00
|
|
|
this.props.mopidyActions.getArtist( props.params.uri );
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 08:57:28 +13:00
|
|
|
loadMore(){
|
2016-11-09 21:13:40 +13:00
|
|
|
if( !this.props.artist.albums_more ) return
|
|
|
|
|
this.props.spotifyActions.getURL( this.props.artist.albums_more, 'SPOTIFY_ARTIST_ALBUMS_LOADED_MORE' );
|
2016-11-01 08:57:28 +13:00
|
|
|
}
|
|
|
|
|
|
2016-11-18 10:02:05 +13:00
|
|
|
play(){
|
|
|
|
|
alert('Yet to be implemented')
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 13:17:07 +13:00
|
|
|
renderSubViewMenu(){
|
2016-11-01 16:41:04 +13:00
|
|
|
return (
|
2016-11-23 13:17:07 +13:00
|
|
|
<div className="sub-views">
|
|
|
|
|
<span className={'option '+( this.state.sub_view == 'overview' ? 'active' : null)} onClick={() => this.setState({ sub_view: 'overview' })}>
|
|
|
|
|
Overview
|
|
|
|
|
</span>
|
|
|
|
|
<span className={'option '+( this.state.sub_view == 'related_artists' ? 'active' : null)} onClick={() => this.setState({ sub_view: 'related_artists' })}>
|
|
|
|
|
Related artists
|
|
|
|
|
</span>
|
|
|
|
|
<span className={'option '+( this.state.sub_view == 'biography' ? 'active' : null)} onClick={() => this.setState({ sub_view: 'biography' })}>
|
|
|
|
|
Biography
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
2016-11-18 10:02:05 +13:00
|
|
|
|
2016-11-23 13:17:07 +13:00
|
|
|
renderBody(){
|
2016-11-18 10:02:05 +13:00
|
|
|
|
2016-11-23 13:17:07 +13:00
|
|
|
if( this.state.sub_view == 'related_artists' ){
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<h4 className="left-padding">Related artists</h4>
|
|
|
|
|
<section className="grid-wrapper no-top-padding">
|
|
|
|
|
{ this.props.artist.related_artists ? <ArtistGrid artists={ this.props.artist.related_artists } /> : null }
|
|
|
|
|
</section>
|
2016-10-17 10:39:11 +13:00
|
|
|
</div>
|
2016-11-23 13:17:07 +13:00
|
|
|
)
|
|
|
|
|
}
|
2016-11-01 16:41:04 +13:00
|
|
|
|
2016-11-23 13:17:07 +13:00
|
|
|
// default body
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
2016-11-01 16:41:04 +13:00
|
|
|
<div className="col w70">
|
|
|
|
|
<h4 className="left-padding">Top tracks</h4>
|
2016-11-09 21:13:40 +13:00
|
|
|
{ this.props.artist.tracks ? <TrackList tracks={ this.props.artist.tracks } /> : null }
|
2016-11-01 16:41:04 +13:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="col w5"></div>
|
|
|
|
|
|
|
|
|
|
<div className="col w25">
|
|
|
|
|
<h4>Related artists</h4>
|
2016-11-09 21:13:40 +13:00
|
|
|
{ this.props.artist.related_artists ? <ArtistList artists={ this.props.artist.related_artists.slice(0,6) } /> : null }
|
2016-11-01 16:41:04 +13:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="cf"></div>
|
|
|
|
|
|
|
|
|
|
<h4 className="left-padding">Albums</h4>
|
2016-11-07 21:21:15 +13:00
|
|
|
<section className="grid-wrapper no-top-padding">
|
2016-11-09 21:13:40 +13:00
|
|
|
{ this.props.artist.albums ? <AlbumGrid albums={ this.props.artist.albums } /> : null }
|
2016-11-07 21:21:15 +13:00
|
|
|
<LazyLoadListener loadMore={ () => this.loadMore() }/>
|
|
|
|
|
</section>
|
2016-11-01 16:41:04 +13:00
|
|
|
</div>
|
2016-11-23 13:17:07 +13:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(){
|
|
|
|
|
if( !this.props.artist ) return null
|
|
|
|
|
var scheme = helpers.uriSource( this.props.params.uri );
|
|
|
|
|
|
2016-11-23 18:19:51 +13:00
|
|
|
var images = []
|
|
|
|
|
if( this.props.artist.images ) images = this.props.artist.images
|
|
|
|
|
|
2016-11-23 13:17:07 +13:00
|
|
|
return (
|
|
|
|
|
<div className="view artist-view">
|
|
|
|
|
|
|
|
|
|
<div className="intro">
|
|
|
|
|
|
2016-11-23 18:19:51 +13:00
|
|
|
<Thumbnail size="huge" images={ images } />
|
|
|
|
|
<Parallax images={ images } />
|
2016-11-23 13:17:07 +13:00
|
|
|
|
|
|
|
|
<div className="heading-wrapper">
|
|
|
|
|
<div className="heading">
|
|
|
|
|
<h1>{ this.props.artist.name }</h1>
|
|
|
|
|
{ this.renderSubViewMenu() }
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="details-wrapper">
|
|
|
|
|
|
|
|
|
|
<div className="actions">
|
|
|
|
|
<button className="large primary" onClick={ e => this.play() }>Start radio</button>
|
|
|
|
|
{ helpers.uriSource(this.props.params.uri) == 'spotify' ? <FollowButton uri={this.props.params.uri} removeText="Unfollow" addText="Follow" /> : null }
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<ul className="details">
|
|
|
|
|
{ this.props.artist.followers ? <li>{ this.props.artist.followers.total.toLocaleString() } followers</li> : null }
|
|
|
|
|
{ this.props.artist.popularity ? <li>{ this.props.artist.popularity }% popularity</li> : null }
|
|
|
|
|
{ scheme == 'local' ? <li>{ this.props.artist.albums.length.toLocaleString() } albums</li> : null }
|
|
|
|
|
{ scheme == 'spotify' ? <li><FontAwesome name='spotify' /> Spotify artist</li> : null }
|
|
|
|
|
{ scheme == 'local' ? <li><FontAwesome name='folder' /> Local artist</li> : null }
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{ this.renderBody() }
|
|
|
|
|
|
|
|
|
|
</div>
|
2016-11-01 16:41:04 +13:00
|
|
|
);
|
|
|
|
|
}
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export our component
|
|
|
|
|
*
|
|
|
|
|
* We also integrate our global store, using connect()
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2016-11-09 21:13:40 +13:00
|
|
|
return {
|
2016-11-18 10:02:05 +13:00
|
|
|
artist: state.ui.artist,
|
|
|
|
|
spotify_authorized: state.spotify.authorized,
|
|
|
|
|
mopidy_connected: state.mopidy.connected
|
2016-11-09 21:13:40 +13:00
|
|
|
}
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
2016-11-01 16:41:04 +13:00
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
2016-11-07 21:21:15 +13:00
|
|
|
lastfmActions: bindActionCreators(lastfmActions, dispatch),
|
2016-10-17 10:39:11 +13:00
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Artist)
|