import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { Link } from 'react-router' 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 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' 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 album if (nextProps.params.uri != this.props.params.uri){ this.loadTrack(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.loadTrack(nextProps ) } } // We don't have lyrics, and we have just received our artists if (!nextProps.track.lyrics && !this.props.track.artists && nextProps.track.artists){ 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) } 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 ); } break; default: if (props.mopidy_connected){ if (props.track){ console.info('Loading track from index') } else { this.props.mopidyActions.getTrack(props.params.uri ); } } break; } } play(){ this.props.mopidyActions.playURIs([this.props.params.uri], this.props.params.uri) } renderLyricsSelector(){ if (!this.props.track.lyrics_results){ return null; } return (
Switch to another lyrics seach result
); } renderLyrics(){ if (helpers.isLoading(this.props.load_queue,['genius_'])){ return (
); } else if (!this.props.track.lyrics){ return (
No lyrics available
) } else { return (
Origin: {this.props.track.lyrics_url}
) } } render(){ if (helpers.isLoading(this.props.load_queue,['spotify_track/'+helpers.getFromUri('trackid',this.props.params.uri)])){ return (
) } if (!this.props.track){ return null } else { var track = this.props.track } return (
{this.props.slim_mode ?
this.handleContextMenu(e)} uiActions={this.props.uiActions} /> : null}

{track.name}

{track.album ? {track.album.name} : "Unknown album"} by

    {!this.props.slim_mode ?
  • {helpers.uriSource(this.props.params.uri)} track
  • : null} {track.date ?
  • : null} {track.explicit ?
  • EXPLICIT
  • : null}
  • {track.disc_number ? Disc {track.disc_number} : null} {track.disc_number && track.track_number ? , : null} {track.track_number ? Track {track.track_number} : null}
  • {track.duration ? : null} {track.length ? : null}
{this.props.slim_mode ? null : this.handleContextMenu(e)} />}
{this.renderLyricsSelector()} {this.renderLyrics()}
) } } /** * Export our component * * We also integrate our global store, using connect() **/ const mapStateToProps = (state, ownProps) => { return { slim_mode: state.ui.slim_mode, load_queue: state.ui.load_queue, track: (state.core.tracks && state.core.tracks[ownProps.params.uri] !== undefined ? state.core.tracks[ownProps.params.uri] : false), tracks: state.core.tracks, artists: state.core.artists, albums: state.core.albums, spotify_library_albums: state.spotify.library_albums, local_library_albums: state.mopidy.library_albums, spotify_authorized: state.spotify.authorization, mopidy_connected: state.mopidy.connected }; } const mapDispatchToProps = (dispatch) => { return { uiActions: bindActionCreators(uiActions, dispatch), uiActions: bindActionCreators(uiActions, dispatch), mopidyActions: bindActionCreators(mopidyActions, dispatch), spotifyActions: bindActionCreators(spotifyActions, dispatch), geniusActions: bindActionCreators(geniusActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(Track)