2016-10-14 22:42:45 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
2016-11-03 18:22:26 +13:00
|
|
|
import { Link } from 'react-router'
|
2016-10-14 22:42:45 +13:00
|
|
|
|
|
|
|
|
import FontAwesome from 'react-fontawesome'
|
2016-11-03 18:22:26 +13:00
|
|
|
import ProgressSlider from './ProgressSlider'
|
2016-10-25 21:36:33 +13:00
|
|
|
import ArtistSentence from './ArtistSentence'
|
2016-10-24 21:26:01 +13:00
|
|
|
import Thumbnail from './Thumbnail'
|
2016-10-23 23:48:06 +13:00
|
|
|
|
|
|
|
|
import * as mopidyActions from '../services/mopidy/actions'
|
2016-10-14 22:42:45 +13:00
|
|
|
|
|
|
|
|
class Player extends React.Component{
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-24 21:26:01 +13:00
|
|
|
renderPlayButton(){
|
|
|
|
|
var button = <a onClick={() => this.props.mopidyActions.play()}><FontAwesome name="play" /> </a>
|
2016-10-14 22:42:45 +13:00
|
|
|
if( this.props.mopidy.state == 'playing' ){
|
2016-10-24 21:26:01 +13:00
|
|
|
button = <a onClick={() => this.props.mopidyActions.pause()}><FontAwesome name="pause" /> </a>
|
2016-10-14 22:42:45 +13:00
|
|
|
}
|
2016-10-24 21:26:01 +13:00
|
|
|
return button;
|
|
|
|
|
}
|
2016-10-14 22:42:45 +13:00
|
|
|
|
2016-10-24 21:26:01 +13:00
|
|
|
renderConsumeButton(){
|
|
|
|
|
var button = <a onClick={() => this.props.mopidyActions.instruct('tracklist.setConsume', [true])}><FontAwesome name="fire" /></a>
|
2016-10-14 22:42:45 +13:00
|
|
|
if( this.props.mopidy.consume ){
|
2016-10-24 21:26:01 +13:00
|
|
|
button = <a className="active" onClick={() => this.props.mopidyActions.instruct('tracklist.setConsume', [false])}><FontAwesome name="fire" /></a>
|
2016-10-14 22:42:45 +13:00
|
|
|
}
|
2016-10-24 21:26:01 +13:00
|
|
|
return button;
|
|
|
|
|
}
|
2016-10-14 22:42:45 +13:00
|
|
|
|
2016-10-24 21:26:01 +13:00
|
|
|
renderRandomButton(){
|
|
|
|
|
var button = <a onClick={() => this.props.mopidyActions.instruct('tracklist.setRandom', [true])}><FontAwesome name="random" /></a>
|
2016-10-14 22:42:45 +13:00
|
|
|
if( this.props.mopidy.random ){
|
2016-10-24 21:26:01 +13:00
|
|
|
button = <a className="active" onClick={() => this.props.mopidyActions.instruct('tracklist.setRandom', [false])}><FontAwesome name="random" /></a>
|
2016-10-14 22:42:45 +13:00
|
|
|
}
|
2016-10-24 21:26:01 +13:00
|
|
|
return button;
|
|
|
|
|
}
|
2016-10-14 22:42:45 +13:00
|
|
|
|
2016-10-24 21:26:01 +13:00
|
|
|
renderRepeatButton(){
|
|
|
|
|
var button = <a onClick={() => this.props.mopidyActions.instruct('tracklist.setRepeat', [true])}><FontAwesome name="repeat" /></a>
|
2016-10-14 22:42:45 +13:00
|
|
|
if( this.props.mopidy.repeat ){
|
2016-10-24 21:26:01 +13:00
|
|
|
button = <a className="active" onClick={() => this.props.mopidyActions.instruct('tracklist.setRepeat', [false])}><FontAwesome name="repeat" /></a>
|
2016-10-14 22:42:45 +13:00
|
|
|
}
|
2016-10-24 21:26:01 +13:00
|
|
|
return button;
|
|
|
|
|
}
|
2016-10-14 22:42:45 +13:00
|
|
|
|
2016-11-03 18:22:26 +13:00
|
|
|
renderMiniPlayer(){
|
|
|
|
|
var mopidy_track = false;
|
|
|
|
|
if( typeof(this.props.mopidy.current_tltrack) !== 'undefined' && typeof(this.props.mopidy.current_tltrack.track) !== 'undefined' ) mopidy_track = this.props.mopidy.current_tltrack;
|
|
|
|
|
|
2016-10-14 22:42:45 +13:00
|
|
|
return (
|
2016-10-23 23:48:06 +13:00
|
|
|
<div className="player">
|
2016-10-24 21:26:01 +13:00
|
|
|
|
2016-11-03 18:22:26 +13:00
|
|
|
<div className="current-track">
|
|
|
|
|
<div className="title">{ mopidy_track ? mopidy_track.track.name : null }</div>
|
|
|
|
|
{ mopidy_track ? <ArtistSentence artists={ mopidy_track.track.artists } /> : null }
|
|
|
|
|
</div>
|
2016-10-14 22:42:45 +13:00
|
|
|
|
2016-10-24 21:26:01 +13:00
|
|
|
<div className="controls">
|
|
|
|
|
<a onClick={() => this.props.mopidyActions.previous()}>
|
|
|
|
|
<FontAwesome name="step-backward" />
|
|
|
|
|
</a>
|
2016-11-03 18:22:26 +13:00
|
|
|
{ this.renderPlayButton() }
|
2016-10-24 21:26:01 +13:00
|
|
|
<a onClick={() => this.props.mopidyActions.next()}>
|
|
|
|
|
<FontAwesome name="step-forward" />
|
|
|
|
|
</a>
|
2016-11-03 18:22:26 +13:00
|
|
|
<ProgressSlider />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderFullPlayer(){
|
|
|
|
|
var mopidy_track = false;
|
2016-11-04 09:35:39 +13:00
|
|
|
var images = [];
|
|
|
|
|
if( typeof(this.props.mopidy.current_tltrack) !== 'undefined' && typeof(this.props.mopidy.current_tltrack.track) !== 'undefined' ){
|
|
|
|
|
mopidy_track = this.props.mopidy.current_tltrack;
|
|
|
|
|
}
|
2016-11-03 18:22:26 +13:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="player">
|
|
|
|
|
|
2016-11-04 09:35:39 +13:00
|
|
|
{ this.props.spotify.track && !this.props.mini ? <Link className="artwork" to={'/album/'+this.props.spotify.track.album.uri}><Thumbnail size="huge" images={this.props.spotify.track.album.images} /></Link> : <Link className="artwork"><Thumbnail size="huge" images={[]} /></Link> }
|
2016-11-03 18:22:26 +13:00
|
|
|
|
|
|
|
|
<div className="controls cf">
|
|
|
|
|
<div className="pull-left">
|
|
|
|
|
<a onClick={() => this.props.mopidyActions.previous()}>
|
|
|
|
|
<FontAwesome name="step-backward" />
|
|
|
|
|
</a>
|
|
|
|
|
{ this.renderPlayButton() }
|
|
|
|
|
<a onClick={() => this.props.mopidyActions.stop()}>
|
|
|
|
|
<FontAwesome name="stop" />
|
|
|
|
|
</a>
|
|
|
|
|
<a onClick={() => this.props.mopidyActions.next()}>
|
|
|
|
|
<FontAwesome name="step-forward" />
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="pull-right">
|
|
|
|
|
{ this.renderConsumeButton() }
|
|
|
|
|
{ this.renderRandomButton() }
|
|
|
|
|
{ this.renderRepeatButton() }
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="current-track">
|
|
|
|
|
<div className="title">{ mopidy_track ? mopidy_track.track.name : null }</div>
|
|
|
|
|
{ mopidy_track ? <ArtistSentence artists={ mopidy_track.track.artists } /> : null }
|
2016-10-24 21:26:01 +13:00
|
|
|
</div>
|
2016-10-14 22:42:45 +13:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-11-03 18:22:26 +13:00
|
|
|
|
|
|
|
|
render(){
|
|
|
|
|
if( this.props.mini ){
|
|
|
|
|
return this.renderMiniPlayer()
|
|
|
|
|
}else{
|
|
|
|
|
return this.renderFullPlayer()
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-14 22:42:45 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export our component
|
|
|
|
|
*
|
|
|
|
|
* We also integrate our global store, using connect()
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
2016-10-23 23:48:06 +13:00
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch)
|
2016-10-14 22:42:45 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Player)
|