import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import FontAwesome from 'react-fontawesome' import Header from '../components/Header' 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 ContextMenuTrigger from '../components/ContextMenuTrigger' import * as helpers from '../helpers' import * as uiActions from '../services/ui/actions' 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() } handleContextMenu(e){ e.preventDefault() var data = { uris: [this.props.params.uri] } this.props.uiActions.showContextMenu( e, data, 'album', 'click' ) } 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 ) != 'spotify' ){ this.loadAlbum( nextProps ) } } } handleContextMenu(e){ var data = { e: e, context: 'album', items: [this.props.album], uris: [this.props.params.uri] } this.props.uiActions.showContextMenu(data) } loadAlbum( props = this.props ){ switch( helpers.uriSource( props.params.uri ) ){ case 'spotify': if (props.album && props.album.tracks && props.album.artists_uris){ console.info('Loading album from index') }else{ this.props.spotifyActions.getAlbum( props.params.uri ); } break; default: if (props.mopidy_connected){ if (props.album && props.album.tracks){ console.info('Loading album from index') } else { this.props.mopidyActions.getAlbum( props.params.uri ); } } break; } } loadMore(){ this.props.spotifyActions.getURL( this.props.album.tracks_more, 'SPOTIFY_ALBUM_LOADED_MORE' ); } play(){ this.props.mopidyActions.playURIs([this.props.params.uri], this.props.params.uri) } inLibrary(){ return (this.props.library_albums && this.props.library_albums.indexOf(this.props.params.uri) > -1) } render(){ if (helpers.isLoading(this.props.load_queue,['spotify_albums/'+helpers.getFromUri('albumid',this.props.params.uri)])){ return (