import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import FontAwesome from 'react-fontawesome'
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 LazyLoadListener from '../components/LazyLoadListener'
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 ){
console.log('componentWillReceiveProps')
// 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.next ) return
this.props.spotifyActions.getURL( this.props.album.tracks.next, 'SPOTIFY_ALBUM_LOADED_MORE' );
}
renderThumbnail(){
if( !this.props.album.images ) return