import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import FontAwesome from 'react-fontawesome' import TrackList from '../components/TrackList' import Thumbnail from '../components/Thumbnail' import Parallax from '../components/Parallax' import ArtistSentence from '../components/ArtistSentence' import ArtistGrid from '../components/ArtistGrid' import FollowButton from '../components/FollowButton' import Dater from '../components/Dater' import LazyLoadListener from '../components/LazyLoadListener' import SidebarToggleButton from '../components/SidebarToggleButton' import * as helpers from '../helpers' import * as mopidyActions from '../services/mopidy/actions' import * as spotifyActions from '../services/spotify/actions' class Album extends React.Component{ constructor(props) { super(props); } componentDidMount(){ this.loadAlbum(); } componentWillReceiveProps( nextProps ){ // if our URI has changed, fetch new album if( nextProps.params.uri != this.props.params.uri ){ this.loadAlbum( nextProps ) // if mopidy has just connected AND we're a local album, go get }else if( !this.props.mopidy_connected && nextProps.mopidy_connected ){ if( helpers.uriSource( this.props.params.uri ) == 'local' ){ this.loadAlbum( nextProps ) } } } loadAlbum( props = this.props ){ switch( helpers.uriSource( props.params.uri ) ){ case 'spotify': this.props.spotifyActions.getAlbum( props.params.uri ); break; case 'local': if( props.mopidy_connected ) this.props.mopidyActions.getAlbum( props.params.uri ); break; } } loadMore(){ if( !this.props.album.tracks_more ) return this.props.spotifyActions.getURL( this.props.album.tracks_more, 'SPOTIFY_ALBUM_LOADED_MORE' ); } play(){ var tracks_uris = helpers.asURIs( this.props.album.tracks ) this.props.mopidyActions.playURIs( tracks_uris ) } render(){ if( !this.props.album ) return null var artists = [] if (this.props.album.artists){ for (var i = 0; i < this.props.album.artists.length; i++){ var uri = this.props.album.artists[i] if (this.props.artists.hasOwnProperty(uri)){ artists.push(this.props.artists[uri]) } } } return (
{ helpers.uriSource(this.props.params.uri) == 'spotify' ? : null }
  • { this.props.album.tracks_total } tracks,  { this.props.album.tracks ? : null }
  • { this.props.album.release_date ?
  • Released
  • : null }
  • {helpers.uriSource( this.props.params.uri )} playlist

{ this.props.album.name }

{ this.props.album.tracks ? : null } this.loadMore() }/>
); } } /** * Export our component * * We also integrate our global store, using connect() **/ const mapStateToProps = (state, ownProps) => { return { artists: state.ui.artists, album: state.ui.albums[ownProps.params.uri], albums: state.ui.albums, spotify_authorized: state.spotify.authorized, mopidy_connected: state.mopidy.connected }; } const mapDispatchToProps = (dispatch) => { return { mopidyActions: bindActionCreators(mopidyActions, dispatch), spotifyActions: bindActionCreators(spotifyActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(Album)