import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' 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/Fields/FollowButton' import Dater from '../components/Dater' import LazyLoadListener from '../components/LazyLoadListener' import ContextMenuTrigger from '../components/ContextMenuTrigger' 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 spotifyActions from '../services/spotify/actions' class Album extends React.Component{ constructor(props){ super(props); } componentDidMount(){ this.setWindowTitle(); this.props.coreActions.loadAlbum(this.props.params.uri); } 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.props.coreActions.loadAlbum(nextProps.params.uri); // 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(nextProps.params.uri) != 'spotify'){ this.props.coreActions.loadAlbum(nextProps.params.uri); } } if (!this.props.album && nextProps.album){ this.setWindowTitle(nextProps.album); } } setWindowTitle(album = this.props.album){ if (album){ var artists = ""; if (album.artists_uris && this.props.artists){ for (var i = 0; i < album.artists_uris.length; i++){ var uri = album.artists_uris[i] if (this.props.artists.hasOwnProperty(uri)){ if (artists != ""){ artists += ", "; } artists += this.props.artists[uri].name; } } } this.props.uiActions.setWindowTitle(album.name+" by "+artists+" (album)"); } else{ this.props.uiActions.setWindowTitle("Album"); } } handleContextMenu(e){ var data = { e: e, context: 'album', items: [this.props.album], uris: [this.props.params.uri] } this.props.uiActions.showContextMenu(data); } loadMore(){ this.props.spotifyActions.getMore( this.props.album.tracks_more, { parent_type: 'album', parent_key: this.props.album.uri, records_type: 'track' } ); } play(){ this.props.mopidyActions.playURIs([this.props.params.uri], this.props.params.uri) } inLibrary(){ var library = helpers.uriSource(this.props.params.uri)+'_library_albums' return (this.props[library] && this.props[library].indexOf(this.props.params.uri) > -1) } render(){ if (!this.props.album){ if (helpers.isLoading(this.props.load_queue,['spotify_albums/'+helpers.getFromUri('albumid',this.props.params.uri)])){ return (