2016-10-17 10:39:11 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
2016-11-01 16:41:04 +13:00
|
|
|
let helpers = require('../helpers.js')
|
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-10-18 21:57:29 +13:00
|
|
|
|
2016-11-01 16:41:04 +13:00
|
|
|
import * as mopidyActions from '../services/mopidy/actions'
|
2016-10-17 10:39:11 +13:00
|
|
|
import * as spotifyActions from '../services/spotify/actions'
|
|
|
|
|
|
|
|
|
|
class Artist extends React.Component{
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
|
}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 );
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 08:57:28 +13:00
|
|
|
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' );
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 16:41:04 +13:00
|
|
|
renderSpotifyAlbum(){
|
|
|
|
|
if( !this.props.spotify.artist ) return null
|
|
|
|
|
var artist = this.props.spotify.artist
|
|
|
|
|
var albums = this.props.spotify.artist_albums
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view artist-view">
|
|
|
|
|
<Parallax images={ artist.images } />
|
|
|
|
|
|
|
|
|
|
<div className="intro">
|
|
|
|
|
<Thumbnail size="huge" images={ artist.images } />
|
|
|
|
|
<h1>{ artist.name }</h1>
|
|
|
|
|
<p>{ artist.followers.total.toLocaleString() } followers</p>
|
2016-10-17 10:39:11 +13:00
|
|
|
</div>
|
2016-11-01 16:41:04 +13:00
|
|
|
|
|
|
|
|
<div className="col w70">
|
|
|
|
|
<h4 className="left-padding">Top tracks</h4>
|
|
|
|
|
{ artist.tracks ? <TrackList tracks={ artist.tracks } /> : null }
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="col w5"></div>
|
|
|
|
|
|
|
|
|
|
<div className="col w25">
|
|
|
|
|
<h4>Related artists</h4>
|
|
|
|
|
{ artist.related_artists ? <ArtistList artists={ artist.related_artists.slice(0,6) } /> : null }
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="cf"></div>
|
|
|
|
|
|
|
|
|
|
<h4 className="left-padding">Albums</h4>
|
|
|
|
|
{ albums ? <AlbumGrid className="no-top-padding" albums={ albums.items } /> : null }
|
|
|
|
|
<LazyLoadListener loadMore={ () => this.loadMore() }/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderMopidyAlbum(){
|
|
|
|
|
if( !this.props.mopidy.artist ) return null
|
|
|
|
|
var artist = this.props.mopidy.artist
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view artist-view">
|
|
|
|
|
<Parallax images={ artist.images } />
|
|
|
|
|
|
|
|
|
|
<div className="intro">
|
|
|
|
|
<Thumbnail size="huge" images={ artist.images } />
|
|
|
|
|
<h1>{ artist.name }</h1>
|
|
|
|
|
</div>
|
|
|
|
|
|
2016-11-01 19:27:59 +13:00
|
|
|
<h4 className="left-padding">Top tracks</h4>
|
|
|
|
|
{ artist.tracks ? <TrackList tracks={ artist.tracks } /> : null }
|
2016-11-01 16:41:04 +13:00
|
|
|
|
|
|
|
|
<h4 className="left-padding">Albums</h4>
|
|
|
|
|
{ artist.albums ? <AlbumGrid className="no-top-padding" albums={ artist.albums } /> : null }
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(){
|
|
|
|
|
var source = helpers.uriSource( this.props.params.uri );
|
|
|
|
|
if( source == 'spotify' ) return this.renderSpotifyAlbum()
|
|
|
|
|
if( source == 'local' ) return this.renderMopidyAlbum()
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export our component
|
|
|
|
|
*
|
|
|
|
|
* We also integrate our global store, using connect()
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
2016-11-01 16:41:04 +13:00
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
2016-10-17 10:39:11 +13:00
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Artist)
|