Files
Iris/src/js/views/Queue.js

169 lines
5.5 KiB
JavaScript
Raw Normal View History

2016-10-03 14:44:27 +13:00
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
2017-06-16 15:40:39 +12:00
import { hashHistory, Link } from 'react-router'
2016-10-03 14:44:27 +13:00
import { bindActionCreators } from 'redux'
import FontAwesome from 'react-fontawesome'
2017-07-26 15:24:18 +12:00
import Parallax from '../components/Parallax'
2016-10-03 15:22:15 +13:00
import TrackList from '../components/TrackList'
2016-10-03 21:21:14 +13:00
import Track from '../components/Track'
2017-01-22 12:54:20 +13:00
import Dater from '../components/Dater'
2016-11-25 22:49:34 +13:00
import SidebarToggleButton from '../components/SidebarToggleButton'
2016-11-04 13:51:17 +13:00
import FullPlayer from '../components/FullPlayer'
2016-10-25 21:36:33 +13:00
import ArtistSentence from '../components/ArtistSentence'
2017-06-16 15:40:39 +12:00
import Thumbnail from '../components/Thumbnail'
import Header from '../components/Header'
2017-07-26 15:24:18 +12:00
import * as helpers from '../helpers'
2016-11-03 18:22:26 +13:00
import * as uiActions from '../services/ui/actions'
2016-12-20 19:54:19 +13:00
import * as pusherActions from '../services/pusher/actions'
2016-11-03 18:22:26 +13:00
import * as spotifyActions from '../services/spotify/actions'
import * as mopidyActions from '../services/mopidy/actions'
2016-10-03 14:44:27 +13:00
2016-10-03 20:05:44 +13:00
class Queue extends React.Component{
2016-10-03 14:44:27 +13:00
constructor(props) {
super(props)
2016-10-03 14:44:27 +13:00
}
removeTracks(track_indexes){
var tlids = []
for (var i = 0; i < track_indexes.length; i++){
tlids.push( this.props.current_tracklist[track_indexes[i]].tlid )
2016-10-19 14:09:34 +13:00
}
this.props.mopidyActions.removeTracks( tlids )
2016-10-19 14:09:34 +13:00
}
playTrack( track ){
this.props.mopidyActions.changeTrack( track.tlid )
}
playTracks( tracks ){
this.props.mopidyActions.changeTrack( tracks[0].tlid )
2016-10-19 14:09:34 +13:00
}
reorderTracks( indexes, index ){
this.props.mopidyActions.reorderTracklist( indexes, index )
}
2017-01-22 12:54:20 +13:00
renderQueueStats(){
var total_time = 0
return (
<div className="queue-stats grey-text">
<span>{this.props.current_tracklist.length} tracks</span>
&nbsp;&nbsp;|&nbsp;&nbsp;
{this.props.current_tracklist.length > 0 ? <Dater type="total-time" data={this.props.current_tracklist} /> : <span>0 mins</span>}
</div>
)
}
2017-07-26 15:24:18 +12:00
renderArtwork(image){
if (!image){
2017-06-16 15:40:39 +12:00
return (
<span className={this.props.radio_enabled ? 'artwork radio-enabled' : 'artwork'}>
{this.props.radio_enabled ? <img className="radio-overlay" src="assets/radio-overlay.png" /> : null}
<Thumbnail size="huge" />
</span>
)
}
var link = null
if( this.props.current_track.album.uri ) link = '/album/'+this.props.current_track.album.uri
return (
2017-07-27 07:48:31 +12:00
<Link className={this.props.radio_enabled ? 'artwork radio-enabled' : 'artwork'} to={link}>
2017-06-16 15:40:39 +12:00
{this.props.radio_enabled ? <img className="radio-overlay" src="assets/radio-overlay.png" /> : null}
2017-07-27 07:48:31 +12:00
<Thumbnail size="huge" image={image} />
2017-06-16 15:40:39 +12:00
</Link>
)
}
2016-10-03 14:44:27 +13:00
render(){
2017-07-26 15:24:18 +12:00
var image = null
if (this.props.current_track && this.props.current_track.album !== undefined && this.props.current_track.album.images){
image = helpers.sizedImages(this.props.current_track.album.images).huge
}
2017-03-06 09:03:20 +13:00
var options = (
<span>
<button className="no-hover" onClick={e => this.props.uiActions.openModal('edit_radio')}>
2017-03-08 09:13:24 +13:00
<FontAwesome name="podcast" />&nbsp;
Radio
2017-04-18 04:44:39 +12:00
{this.props.radio && this.props.radio.enabled ? <span className="flag blue">On</span> : null}
</button>
<button className="no-hover" onClick={e => hashHistory.push(global.baseURL+'queue/history')}>
2017-02-10 09:06:41 +13:00
<FontAwesome name="history" />&nbsp;
History
</button>
<button className="no-hover" onClick={e => this.props.mopidyActions.clearTracklist()}>
2017-03-08 09:13:24 +13:00
<FontAwesome name="trash" />&nbsp;
Clear
</button>
<button className="no-hover" onClick={e => this.props.uiActions.openModal('add_to_queue', {})}>
2017-03-08 09:13:24 +13:00
<FontAwesome name="plus" />&nbsp;
Add URI
</button>
</span>
2017-01-22 12:54:20 +13:00
)
2016-10-03 14:44:27 +13:00
return (
2017-01-30 16:59:37 +13:00
<div className="view queue-view">
2017-07-26 15:24:18 +12:00
<Header icon="play" className="overlay" title="Now playing" options={options} uiActions={this.props.uiActions} />
<Parallax blur image={image} />
2017-06-16 15:40:39 +12:00
2017-06-18 05:47:36 +12:00
<div className="content-wrapper">
<div className="current-track">
2017-07-26 15:24:18 +12:00
{ this.renderArtwork(image) }
2017-06-18 05:47:36 +12:00
<div className="title">
{this.props.current_track ? this.props.current_track.name : <span>-</span>}
</div>
{this.props.current_track ? <ArtistSentence artists={ this.props.current_track.artists } /> : <ArtistSentence />}
2017-06-16 15:40:39 +12:00
</div>
2016-11-04 15:55:17 +13:00
2017-06-18 05:47:36 +12:00
<section className="list-wrapper">
<TrackList
show_source_icon={true}
context="queue"
className="queue-track-list"
tracks={this.props.current_tracklist}
removeTracks={tracks => this.removeTracks( tracks )}
playTracks={tracks => this.playTracks( tracks )}
playTrack={track => this.playTrack( track )}
reorderTracks={(indexes, index) => this.reorderTracks(indexes, index) } />
2017-06-18 05:47:36 +12:00
</section>
2016-11-04 15:55:17 +13:00
2017-06-18 05:47:36 +12:00
</div>
2016-10-03 14:44:27 +13:00
</div>
);
}
}
/**
* Export our component
*
* We also integrate our global store, using connect()
**/
const mapStateToProps = (state, ownProps) => {
return {
2016-12-20 16:58:20 +13:00
radio: state.ui.radio,
2017-06-16 15:40:39 +12:00
radio_enabled: (state.ui.radio && state.ui.radio.enabled ? true : false),
current_tracklist: state.ui.current_tracklist,
2017-07-26 15:24:18 +12:00
current_track: (state.ui.current_track !== undefined && state.ui.tracks !== undefined && state.ui.tracks[state.ui.current_track.uri] !== undefined ? state.ui.tracks[state.ui.current_track.uri] : null)
}
2016-10-03 14:44:27 +13:00
}
const mapDispatchToProps = (dispatch) => {
return {
2016-11-03 18:22:26 +13:00
uiActions: bindActionCreators(uiActions, dispatch),
2016-12-20 19:54:19 +13:00
pusherActions: bindActionCreators(pusherActions, dispatch),
2016-11-03 18:22:26 +13:00
spotifyActions: bindActionCreators(spotifyActions, dispatch),
mopidyActions: bindActionCreators(mopidyActions, dispatch)
2016-10-03 14:44:27 +13:00
}
}
2016-10-03 20:05:44 +13:00
export default connect(mapStateToProps, mapDispatchToProps)(Queue)