import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { hashHistory, Link } from 'react-router' import { bindActionCreators } from 'redux' import FontAwesome from 'react-fontawesome' import Parallax from '../components/Parallax' import TrackList from '../components/TrackList' import Track from '../components/Track' import Dater from '../components/Dater' import ArtistSentence from '../components/ArtistSentence' import Thumbnail from '../components/Thumbnail' import Header from '../components/Header' import URILink from '../components/URILink' import * as helpers from '../helpers' import * as uiActions from '../services/ui/actions' import * as pusherActions from '../services/pusher/actions' import * as spotifyActions from '../services/spotify/actions' import * as mopidyActions from '../services/mopidy/actions' class Queue extends React.Component{ constructor(props){ super(props) } removeTracks(track_indexes){ var tlids = []; for (var i = 0; i < track_indexes.length; i++){ var uri = this.props.queue[track_indexes[i]]; if (this.props.tracks[uri] !== undefined){ tlids.push(this.props.tracks[uri].tlid); } } if (tlids.length > 0){ this.props.mopidyActions.removeTracks(tlids); } } playTrack(track){ this.props.mopidyActions.changeTrack(track.tlid ) } playTracks(tracks){ this.props.mopidyActions.changeTrack(tracks[0].tlid ) } reorderTracks(indexes, index){ this.props.mopidyActions.reorderTracklist(indexes, index ) } renderQueueStats(){ var total_time = 0 return (
{this.props.current_tracklist.length} tracks   |   {this.props.current_tracklist.length > 0 ? : 0 mins}
) } renderArtwork(image){ if (!image){ return ( {this.props.radio_enabled ? : null} ) } var uri = null if (this.props.current_track.album && this.props.current_track.album.uri){ uri = this.props.current_track.album.uri; } return ( {this.props.radio_enabled ? : null} ) } render(){ var image = null if (this.props.current_track){ if (this.props.current_track.images !== undefined && this.props.current_track.images){ image = helpers.sizedImages(this.props.current_track.images) image = image.large } } var tracks = []; if (this.props.queue && this.props.tracks){ for (var i = 0; i < this.props.queue.length; i++){ var uri = this.props.queue[i]; if (this.props.tracks.hasOwnProperty(uri)){ var track = this.props.tracks[uri]; track.playing = (track.uri == this.props.current_track_uri); tracks.push(track); } } } // Merge our metadata with each track for (var i = 0; i < tracks.length; i++){ var track = tracks[i]; if (this.props.queue_metadata["tlid_"+track.tlid] !== undefined){ track = Object.assign( {}, track, this.props.queue_metadata["tlid_"+track.tlid] ); tracks[i] = track; } } var options = ( {this.props.spotify_enabled ? : null} ) return (
{ this.renderArtwork(image) }
{this.props.current_track ? {this.props.current_track.name} : -}
{this.props.current_track ? : }
this.removeTracks(tracks)} playTracks={tracks => this.playTracks(tracks)} playTrack={track => this.playTrack(track)} reorderTracks={(indexes, index) => this.reorderTracks(indexes, index)} />
); } } /** * Export our component * * We also integrate our global store, using connect() **/ const mapStateToProps = (state, ownProps) => { return { spotify_enabled: state.spotify.enabled, radio: state.core.radio, radio_enabled: (state.core.radio && state.core.radio.enabled ? true : false), tracks: state.core.tracks, queue: state.core.queue, queue_metadata: state.core.queue_metadata, current_track_uri: state.core.current_track_uri, current_track: (state.core.tracks[state.core.current_track_uri] !== undefined ? state.core.tracks[state.core.current_track_uri] : null) } } const mapDispatchToProps = (dispatch) => { return { uiActions: bindActionCreators(uiActions, dispatch), pusherActions: bindActionCreators(pusherActions, dispatch), spotifyActions: bindActionCreators(spotifyActions, dispatch), mopidyActions: bindActionCreators(mopidyActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(Queue)