Files
Iris/src/js/components/Player.js

144 lines
4.7 KiB
JavaScript
Raw Normal View History

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'
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'
import * as mopidyActions from '../services/mopidy/actions'
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>
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-24 21:26:01 +13:00
return button;
}
2016-10-24 21:26:01 +13:00
renderConsumeButton(){
var button = <a onClick={() => this.props.mopidyActions.instruct('tracklist.setConsume', [true])}><FontAwesome name="fire" /></a>
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-24 21:26:01 +13:00
return button;
}
2016-10-24 21:26:01 +13:00
renderRandomButton(){
var button = <a onClick={() => this.props.mopidyActions.instruct('tracklist.setRandom', [true])}><FontAwesome name="random" /></a>
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-24 21:26:01 +13:00
return button;
}
2016-10-24 21:26:01 +13:00
renderRepeatButton(){
var button = <a onClick={() => this.props.mopidyActions.instruct('tracklist.setRepeat', [true])}><FontAwesome name="repeat" /></a>
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-24 21:26:01 +13:00
return button;
}
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;
return (
<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-24 21:26:01 +13:00
<div className="controls">
<a onClick={() => this.props.mopidyActions.previous()}>
<FontAwesome name="step-backward" />
</a>&nbsp;
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>&nbsp;
2016-11-03 18:22:26 +13:00
<ProgressSlider />
</div>
</div>
);
}
renderFullPlayer(){
var mopidy_track = false;
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">
{ 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>&nbsp;
{ this.renderPlayButton() }
<a onClick={() => this.props.mopidyActions.stop()}>
<FontAwesome name="stop" />
</a>&nbsp;
<a onClick={() => this.props.mopidyActions.next()}>
<FontAwesome name="step-forward" />
</a>&nbsp;
</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>
</div>
);
}
2016-11-03 18:22:26 +13:00
render(){
if( this.props.mini ){
return this.renderMiniPlayer()
}else{
return this.renderFullPlayer()
}
}
}
/**
* Export our component
*
* We also integrate our global store, using connect()
**/
const mapStateToProps = (state, ownProps) => {
return state;
}
const mapDispatchToProps = (dispatch) => {
return {
mopidyActions: bindActionCreators(mopidyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Player)