import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { Link } from 'react-router' import { bindActionCreators } from 'redux' import Header from '../components/Header' import TrackList from '../components/TrackList' import Thumbnail from '../components/Thumbnail' import ArtistSentence from '../components/ArtistSentence' import ArtistGrid from '../components/ArtistGrid' import FollowButton from '../components/Fields/FollowButton' import LastfmLoveButton from '../components/Fields/LastfmLoveButton' import Dater from '../components/Dater' import LazyLoadListener from '../components/LazyLoadListener' import ContextMenuTrigger from '../components/ContextMenuTrigger' import URILink from '../components/URILink' 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' import * as lastfmActions from '../services/lastfm/actions' import * as geniusActions from '../services/genius/actions' class Track extends React.Component{ constructor(props){ super(props); } componentDidMount(){ this.loadTrack(); } handleContextMenu(e){ e.preventDefault() var data = { uris: [this.props.params.uri] } this.props.uiActions.showContextMenu(e, data, 'track', 'click' ) } componentWillReceiveProps(nextProps){ // if our URI has changed, fetch new track if (nextProps.params.uri != this.props.params.uri){ this.loadTrack(nextProps) // if mopidy has just connected AND we're not a Spotify track, go get } else if (!this.props.mopidy_connected && nextProps.mopidy_connected){ if (helpers.uriSource(this.props.params.uri) != 'spotify'){ this.loadTrack(nextProps); } } // We have just received our full track info (with artists) if (!this.props.track.artists && nextProps.track.artists){ // Ready to load LastFM if (nextProps.lastfm_authorized){ this.props.lastfmActions.getTrack(nextProps.track.uri); } // Ready to load lyrics if (!nextProps.track.lyrics_results){ this.props.geniusActions.findTrackLyrics(nextProps.track); } } } handleContextMenu(e){ var data = { e: e, context: 'track', items: [this.props.track], uris: [this.props.params.uri] } this.props.uiActions.showContextMenu(data) } /** * TODO: Identify why images being loaded breaks the thumbnail. Is there a new image array format * we need to accommodate? **/ loadTrack(props = this.props){ switch (helpers.uriSource(props.params.uri)){ case 'spotify': if (props.track){ console.info('Loading track from index'); } else { this.props.spotifyActions.getTrack(props.params.uri); this.props.spotifyActions.following(props.params.uri); } break; default: if (props.mopidy_connected){ if (props.track){ console.info('Loading track from index'); } else { this.props.mopidyActions.getTrack(props.params.uri ); } } break; } // We have artist info already if (props.track && props.track.artists){ // Get the LastFM version of this track (provided we have artist info) if (props.lastfm_authorized){ this.props.lastfmActions.getTrack(props.track.uri); } // Ready for lyrics if (props.track && !props.track.lyrics_results){ this.props.geniusActions.findTrackLyrics(props.track); } } } play(){ this.props.mopidyActions.playURIs([this.props.params.uri], this.props.params.uri) } renderLyricsSelector(){ if (this.props.track.lyrics_results === undefined || this.props.track.lyrics_results === null){ return null; } else if (this.props.track.lyrics_results.length <= 0){ return (