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-11-24 08:11:41 +13:00
|
|
|
import SidebarToggleButton from '../components/SidebarToggleButton'
|
2016-10-18 21:57:29 +13:00
|
|
|
|
2016-11-18 13:21:30 +13:00
|
|
|
import * as helpers from '../helpers'
|
2016-12-20 16:58:20 +13:00
|
|
|
import * as uiActions from '../services/ui/actions'
|
2016-11-01 16:41:04 +13:00
|
|
|
import * as mopidyActions from '../services/mopidy/actions'
|
2016-12-20 16:58:20 +13:00
|
|
|
import * as pusherActions from '../services/pusher/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 )
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-25 09:12:56 +13:00
|
|
|
componentWillUpdate( nextProps, nextState ){
|
2017-02-07 20:07:04 +13:00
|
|
|
if( nextState.sub_view != this.state.sub_view && nextState.sub_view == 'about' ){
|
2016-11-25 09:12:56 +13:00
|
|
|
if( this.props.artist && !this.props.artist.bio ){
|
2017-01-15 21:06:24 +13:00
|
|
|
this.props.lastfmActions.getArtist( this.props.params.uri, this.props.artist.name.replace('&','and') )
|
2016-11-25 09:12:56 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 16:41:04 +13:00
|
|
|
loadArtist( props = this.props ){
|
2017-01-15 11:40:08 +13:00
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case 'local':
|
2017-01-15 21:06:24 +13:00
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-15 11:40:08 +13:00
|
|
|
break
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
2017-01-09 09:29:56 +13:00
|
|
|
|
|
|
|
|
// go back to overview
|
|
|
|
|
this.setState({ sub_view: 'overview' })
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
2016-11-01 08:57:28 +13:00
|
|
|
loadMore(){
|
2017-01-15 11:40:08 +13:00
|
|
|
this.props.spotifyActions.getURL( this.props.artist.albums_more, 'SPOTIFY_ARTIST_ALBUMS_LOADED', this.props.params.uri );
|
2016-11-01 08:57:28 +13:00
|
|
|
}
|
|
|
|
|
|
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>
|
2017-01-15 21:06:24 +13:00
|
|
|
{this.props.artist.related_artists_uris ? <span className={'option '+( this.state.sub_view == 'related_artists' ? 'active' : null)} onClick={() => this.setState({ sub_view: 'related_artists' })}>Related artists</span> : null}
|
2017-02-07 20:07:04 +13:00
|
|
|
<span className={'option '+( this.state.sub_view == 'about' ? 'active' : null)} onClick={() => this.setState({ sub_view: 'about' })}>
|
|
|
|
|
About
|
2016-11-23 13:17:07 +13:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
2016-11-18 10:02:05 +13:00
|
|
|
|
2016-11-23 13:17:07 +13:00
|
|
|
renderBody(){
|
2017-02-07 10:00:29 +13:00
|
|
|
var scheme = helpers.uriSource( this.props.params.uri );
|
|
|
|
|
|
2017-01-14 10:03:45 +13:00
|
|
|
var related_artists = []
|
2017-01-15 11:40:08 +13:00
|
|
|
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]
|
2017-01-14 10:03:45 +13:00
|
|
|
if (this.props.artists.hasOwnProperty(uri)){
|
|
|
|
|
related_artists.push(this.props.artists[uri])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var albums = []
|
2017-01-15 11:40:08 +13:00
|
|
|
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]
|
2017-01-14 10:03:45 +13:00
|
|
|
if (this.props.albums.hasOwnProperty(uri)){
|
|
|
|
|
albums.push(this.props.albums[uri])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 13:17:07 +13:00
|
|
|
if( this.state.sub_view == 'related_artists' ){
|
|
|
|
|
return (
|
2016-11-24 08:11:41 +13:00
|
|
|
<div className="body related-artists">
|
2016-11-23 13:17:07 +13:00
|
|
|
<h4 className="left-padding">Related artists</h4>
|
|
|
|
|
<section className="grid-wrapper no-top-padding">
|
2017-01-14 10:03:45 +13:00
|
|
|
<ArtistGrid artists={related_artists} />
|
2016-11-23 13:17:07 +13:00
|
|
|
</section>
|
2016-10-17 10:39:11 +13:00
|
|
|
</div>
|
2016-11-23 13:17:07 +13:00
|
|
|
)
|
2017-02-07 20:07:04 +13:00
|
|
|
}else if( this.state.sub_view == 'about' ){
|
2016-11-23 21:42:56 +13:00
|
|
|
return (
|
2017-02-08 20:05:37 +13:00
|
|
|
<div className="body about">
|
2017-02-08 19:31:36 +13:00
|
|
|
|
|
|
|
|
<div className="col w40 tiles">
|
2017-02-08 20:05:37 +13:00
|
|
|
{this.props.artist.followers ? <div className="tile"><span className="text"><FontAwesome name="users" />{this.props.artist.followers.total.toLocaleString() } followers</span></div> : null}
|
|
|
|
|
{this.props.artist.popularity ? <div className="tile"><span className="text"><FontAwesome name="fire" />{this.props.artist.popularity }% popularity</span></div> : null}
|
|
|
|
|
{this.props.artist.listeners ? <div className="tile"><span className="text"><FontAwesome name="headphones" />{ this.props.artist.listeners.toLocaleString() } listeners</span></div> : null }
|
2017-02-08 19:31:36 +13:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="col w60 biography">
|
|
|
|
|
<h4 className="left-padding">Biography</h4>
|
|
|
|
|
<section className="text-wrapper no-top-padding">
|
|
|
|
|
{ this.props.artist.bio ? <div><p>{this.props.artist.bio.content}</p><br />
|
|
|
|
|
<div className="grey-text">Published: { this.props.artist.bio.published }</div>
|
|
|
|
|
<div className="grey-text">Origin: <a href={ this.props.artist.bio.links.link.href } target="_blank">{ this.props.artist.bio.links.link.href }</a></div></div> : null }
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
2016-11-23 21:42:56 +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
|
|
|
return (
|
2016-11-24 08:11:41 +13:00
|
|
|
<div className="body overview">
|
2017-01-16 08:11:32 +13:00
|
|
|
<div className={related_artists.length > 0 ? "col w70" : "col w100"}>
|
2016-11-01 16:41:04 +13:00
|
|
|
<h4 className="left-padding">Top tracks</h4>
|
2017-01-29 16:25:05 +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>
|
|
|
|
|
|
2017-01-16 08:11:32 +13:00
|
|
|
{related_artists.length > 0 ? <div className="col w25 related-artists"><h4>Related artists</h4><ArtistList artists={related_artists.slice(0,6)} /></div> : null}
|
2016-11-01 16:41:04 +13:00
|
|
|
|
|
|
|
|
<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">
|
2017-01-14 10:03:45 +13:00
|
|
|
<AlbumGrid albums={albums} />
|
2017-01-27 08:15:59 +13:00
|
|
|
<LazyLoadListener enabled={this.props.artist.albums_more} loadMore={ () => this.loadMore() }/>
|
2016-11-07 21:21:15 +13:00
|
|
|
</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 );
|
|
|
|
|
|
2017-01-15 21:06:24 +13:00
|
|
|
var image = null
|
2016-11-28 08:24:01 +13:00
|
|
|
if( this.props.artist.images ) image = helpers.sizedImages( this.props.artist.images ).huge
|
2016-11-23 18:19:51 +13:00
|
|
|
|
2016-11-23 13:17:07 +13:00
|
|
|
return (
|
|
|
|
|
<div className="view artist-view">
|
|
|
|
|
|
2016-11-24 08:11:41 +13:00
|
|
|
<SidebarToggleButton />
|
|
|
|
|
|
2016-11-23 13:17:07 +13:00
|
|
|
<div className="intro">
|
|
|
|
|
|
2017-02-08 08:34:14 +13:00
|
|
|
<Parallax image={image} />
|
2016-11-23 13:17:07 +13:00
|
|
|
|
2017-02-07 10:00:29 +13:00
|
|
|
<div className="liner">
|
2017-02-08 08:34:14 +13:00
|
|
|
<Thumbnail image={image} circle />
|
2017-02-07 10:00:29 +13:00
|
|
|
<h1>{ this.props.artist.name }</h1>
|
2017-02-08 19:31:36 +13:00
|
|
|
{ scheme == 'spotify' ? <div className="actions"><button className="primary rounded" onClick={e => this.props.pusherActions.startRadio([this.props.artist.uri])}>Start radio</button><FollowButton className="outline rounded white" uri={this.props.params.uri} removeText="Unfollow" addText="Follow" is_following={this.props.artist.is_following} /></div> : null}
|
2017-02-07 10:00:29 +13:00
|
|
|
{ this.renderSubViewMenu() }
|
2016-11-23 13:17:07 +13:00
|
|
|
</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 {
|
2017-01-14 22:32:39 +13:00
|
|
|
artist: (state.ui.artists && typeof(state.ui.artists[ownProps.params.uri]) !== 'undefined' ? state.ui.artists[ownProps.params.uri] : false ),
|
2017-01-14 10:03:45 +13:00
|
|
|
artists: state.ui.artists,
|
|
|
|
|
albums: state.ui.albums,
|
2016-11-18 10:02:05 +13:00
|
|
|
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-12-20 16:58:20 +13:00
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
2016-11-01 16:41:04 +13:00
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
2016-12-20 16:58:20 +13:00
|
|
|
pusherActions: bindActionCreators(pusherActions, 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)
|