import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import Link from '../components/Link'; 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 ArtistGrid from '../components/ArtistGrid' import RelatedArtists from '../components/RelatedArtists' import FollowButton from '../components/Fields/FollowButton' import ContextMenuTrigger from '../components/ContextMenuTrigger' import DropdownField from '../components/Fields/DropdownField' import Icon from '../components/Icon' import * as helpers from '../helpers' import * as coreActions from '../services/core/actions' import * as uiActions from '../services/ui/actions' import * as mopidyActions from '../services/mopidy/actions' import * as pusherActions from '../services/pusher/actions' import * as lastfmActions from '../services/lastfm/actions' import * as spotifyActions from '../services/spotify/actions' class Artist extends React.Component{ constructor(props){ super(props) } componentDidMount(){ this.setWindowTitle(); this.props.coreActions.loadArtist(this.props.params.uri); } componentWillReceiveProps(nextProps){ if (nextProps.params.uri != this.props.params.uri){ this.props.coreActions.loadArtist(nextProps.params.uri); }else if (!this.props.mopidy_connected && nextProps.mopidy_connected){ if (helpers.uriSource(this.props.params.uri ) != 'spotify'){ this.props.coreActions.loadArtist(nextProps.params.uri); } } if (!this.props.artist && nextProps.artist){ this.setWindowTitle(nextProps.artist); } if (this.props.params.uri !== nextProps.params.uri && nextProps.artist){ this.setWindowTitle(nextProps.artist); } } setWindowTitle(artist = this.props.artist){ if (artist){ this.props.uiActions.setWindowTitle(artist.name+" (artist)"); } else{ this.props.uiActions.setWindowTitle("Artist"); } } handleContextMenu(e){ var data = { e: e, context: 'artist', items: [this.props.artist], uris: [this.props.params.uri] } this.props.uiActions.showContextMenu(data); } loadMore(){ this.props.spotifyActions.getMore( this.props.artist.albums_more, { parent_type: 'artist', parent_key: this.props.params.uri, records_type: 'album' } ); } inLibrary(){ var library = helpers.uriSource(this.props.params.uri)+'_library_artists' return (this.props[library] && this.props[library].indexOf(this.props.params.uri) > -1) } setSort(value){ var reverse = false if (this.props.sort == value ) reverse = !this.props.sort_reverse var data = { artist_albums_sort_reverse: reverse, artist_albums_sort: value } this.props.uiActions.set(data) } setFilter(value){ this.props.uiActions.set({artist_albums_filter: value}); } renderSubViewMenu(){ return (

Overview

{this.props.artist.related_artists_uris ?

Related artists

: null}

About

) } renderBody(){ var scheme = helpers.uriSource(this.props.params.uri); var artist = helpers.collate( this.props.artist, { artists: this.props.artists, albums: this.props.albums, tracks: this.props.tracks } ); if (this.props.sort && artist.albums){ artist.albums = helpers.sortItems(artist.albums, this.props.sort, this.props.sort_reverse); } if (this.props.filter && artist.albums){ artist.albums = helpers.applyFilter('type', this.props.filter, artist.albums); } switch (this.props.params.sub_view){ case 'related-artists': return (
) case 'about': return (
{artist.images ?
: null} {artist.images_additional ?
: null} {artist.followers ?
{artist.followers.toLocaleString()} followers
: null} {artist.popularity ?
{artist.popularity }% popularity
: null} {artist.listeners ?
{ artist.listeners.toLocaleString() } listeners
: null }
{ artist.biography ?

{artist.biography}


Published: { artist.biography_publish_date }
Origin: { artist.biography_link }
: null }
) default: var sort_options = [ { value: null, label: 'Default' }, { value: 'name', label: 'Name' }, { value: 'date', label: 'Date' }, { value: 'tracks_total', label: 'Tracks' } ]; var filter_options = [ { value: null, label: 'All' }, { value: 'album', label: 'Albums' }, { value: 'single', label: 'Singles' }, { value: 'compilation', label: 'Compilations' } ]; if (!artist.tracks_uris || (artist.tracks_uris && !artist.tracks) || (artist.tracks_uris.length !== artist.tracks.length)){ var is_loading_tracks = true; } else { var is_loading_tracks = false; } return (
0 ? "70" : "100")}>

Top tracks

{artist.related_artists && artist.related_artists.length > 0 ?

Related artists

All related artists
: null}

Albums {this.setSort(value); this.props.uiActions.hideContextMenu() }} /> {this.setFilter(value); this.props.uiActions.hideContextMenu() }} />

this.loadMore()} />
) } } render(){ var scheme = helpers.uriSource(this.props.params.uri); if (!this.props.artist){ if (helpers.isLoading(this.props.load_queue,['spotify_artists/'+helpers.getFromUri('artistid',this.props.params.uri), 'lastfm_method=artist.getInfo'])){ return (
) } else { return null; } } if (this.props.artist && this.props.artist.images){ var image = this.props.artist.images.huge; } else { var image = null; } var is_spotify = (scheme == 'spotify') if (this.props.artist.tracks_uris && this.props.artist.tracks_uris.length > 0){ var uris_to_play = this.props.artist.tracks_uris } else { var uris_to_play = this.props.artist.albums_uris } return (

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

{is_spotify ? : null} this.handleContextMenu(e)} />
{ this.renderSubViewMenu() }
{this.renderBody()}
); } } /** * Export our component * * We also integrate our global store, using connect() **/ const mapStateToProps = (state, ownProps) => { var uri = ownProps.params.uri; return { disable_parallax: state.ui.disable_parallax, theme: state.ui.theme, slim_mode: state.ui.slim_mode, load_queue: state.ui.load_queue, artist: (state.core.artists[uri] !== undefined ? state.core.artists[uri] : false), tracks: state.core.tracks, artists: state.core.artists, spotify_library_artists: state.spotify.library_artists, local_library_artists: state.mopidy.library_artists, albums: (state.core.albums ? state.core.albums : []), filter: (state.ui.artist_albums_filter ? state.ui.artist_albums_filter : null), sort: (state.ui.artist_albums_sort ? state.ui.artist_albums_sort : null), sort_reverse: (state.ui.artist_albums_sort_reverse ? true : false), spotify_authorized: state.spotify.authorization, mopidy_connected: state.mopidy.connected } } const mapDispatchToProps = (dispatch) => { return { coreActions: bindActionCreators(coreActions, dispatch), uiActions: bindActionCreators(uiActions, dispatch), mopidyActions: bindActionCreators(mopidyActions, dispatch), pusherActions: bindActionCreators(pusherActions, dispatch), lastfmActions: bindActionCreators(lastfmActions, dispatch), spotifyActions: bindActionCreators(spotifyActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(Artist)