import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' let helpers = require('../helpers.js') 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 Dater from '../components/Dater' import * as spotifyActions from '../services/spotify/actions' import * as mopidyActions from '../services/mopidy/actions' class Album extends React.Component{ constructor(props) { super(props); } componentDidMount(){ this.loadAlbum(); } componentWillReceiveProps( nextProps ){ if( nextProps.params.uri != this.props.params.uri ){ this.loadAlbum( nextProps ) }else if( !this.props.mopidy.connected && nextProps.mopidy.connected ){ if( helpers.uriSource( this.props.params.uri ) == 'local' ){ this.loadAlbum( nextProps ) } } } loadAlbum( props = this.props ){ var source = helpers.uriSource( props.params.uri ); if( source == 'spotify' ){ this.props.spotifyActions.getAlbum( props.params.uri ); }else if( source == 'local' && props.mopidy.connected ){ this.props.mopidyActions.getAlbum( props.params.uri ); } } totalTime( tracks = [] ){ var duration = 0; for( var i = 0; i < tracks.length; i++ ){ if( tracks[i].duration_ms ) duration += parseInt(tracks[i].duration_ms); if( tracks[i].length ) duration += parseInt(tracks[i].length); } return duration; } render(){ var source = helpers.uriSource( this.props.params.uri ); if( source == 'spotify' ) var album = this.props.spotify.album if( source == 'local' ) var album = this.props.mopidy.album if( !album ) return null; return (
{ album.tracks.total } tracks, mins
{ album.release_date ?
Released
: null }

{ album.name }

); } } /** * Export our component * * We also integrate our global store, using connect() **/ const mapStateToProps = (state, ownProps) => { return state; } const mapDispatchToProps = (dispatch) => { return { mopidyActions: bindActionCreators(mopidyActions, dispatch), spotifyActions: bindActionCreators(spotifyActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(Album)