2017-06-16 09:37:40 +12:00
import React , { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import FontAwesome from 'react-fontawesome'
import ProgressSlider from './ProgressSlider'
import VolumeControl from './VolumeControl'
import Dater from './Dater'
import ArtistSentence from './ArtistSentence'
import Thumbnail from './Thumbnail'
import * as mopidyActions from '../services/mopidy/actions'
class PlaybackControls extends React . Component {
constructor ( props ) {
super ( props ) ;
}
renderPlayButton ( ) {
var button = < a className = "control play" onClick = { ( ) => this . props . mopidyActions . play ( ) } > < FontAwesome name = "play" / > < / a >
if ( this . props . play _state == 'playing' ) {
button = < a className = "control play" onClick = { ( ) => this . props . mopidyActions . pause ( ) } > < FontAwesome name = "pause" / > < / a >
}
return button ;
}
renderConsumeButton ( ) {
var button = < a className = "control has-tooltip" onClick = { ( ) => this . props . mopidyActions . instruct ( 'tracklist.setConsume' , [ true ] ) } > < FontAwesome name = "fire" / > < span className = "tooltip" > Consume < / s p a n > < / a >
if ( this . props . consume ) {
button = < a className = "control active has-tooltip" onClick = { ( ) => this . props . mopidyActions . instruct ( 'tracklist.setConsume' , [ false ] ) } > < FontAwesome name = "fire" / > < span className = "tooltip" > Consume < / s p a n > < / a >
}
return button ;
}
renderRandomButton ( ) {
var button = < a className = "control has-tooltip" onClick = { ( ) => this . props . mopidyActions . instruct ( 'tracklist.setRandom' , [ true ] ) } > < FontAwesome name = "random" / > < span className = "tooltip" > Shuffle < / s p a n > < / a >
if ( this . props . random ) {
button = < a className = "control active has-tooltip" onClick = { ( ) => this . props . mopidyActions . instruct ( 'tracklist.setRandom' , [ false ] ) } > < FontAwesome name = "random" / > < span className = "tooltip" > Shuffle < / s p a n > < / a >
}
return button ;
}
renderRepeatButton ( ) {
var button = < a className = "control has-tooltip" onClick = { ( ) => this . props . mopidyActions . instruct ( 'tracklist.setRepeat' , [ true ] ) } > < FontAwesome name = "repeat" / > < span className = "tooltip" > Repeat < / s p a n > < / a >
if ( this . props . repeat ) {
button = < a className = "control active has-tooltip" onClick = { ( ) => this . props . mopidyActions . instruct ( 'tracklist.setRepeat' , [ false ] ) } > < FontAwesome name = "repeat" / > < span className = "tooltip" > Repeat < / s p a n > < / a >
}
return button ;
}
render ( ) {
var images = [ ]
if ( this . props . current _track && this . props . current _track . album && this . props . current _track . album . images ) {
images = this . props . current _track . album . images
}
return (
< div className = "playback-controls" >
2017-06-16 09:44:19 +12:00
< a className = "current-track" >
2017-06-16 09:37:40 +12:00
< Thumbnail size = "small" images = { images } / >
< div className = "title" >
{ this . props . current _track ? this . props . current _track . name : < span > - < / s p a n > }
< / d i v >
< div className = "artist" >
2017-06-16 09:44:19 +12:00
{ this . props . current _track ? < ArtistSentence nolinks artists = { this . props . current _track . artists } / > : < ArtistSentence / > }
2017-06-16 09:37:40 +12:00
< / d i v >
2017-06-16 09:44:19 +12:00
< / a >
2017-06-16 09:37:40 +12:00
< section className = "playback" >
< a className = "control" onClick = { ( ) => this . props . mopidyActions . previous ( ) } >
< FontAwesome name = "step-backward" / >
< / a >
{ this . renderPlayButton ( ) }
< a className = "control" onClick = { ( ) => this . props . mopidyActions . stop ( ) } >
< FontAwesome name = "stop" / >
< / a >
< a className = "control" onClick = { ( ) => this . props . mopidyActions . next ( ) } >
< FontAwesome name = "step-forward" / >
< / a >
< / s e c t i o n >
< section className = "settings" >
{ this . renderConsumeButton ( ) }
{ this . renderRandomButton ( ) }
{ this . renderRepeatButton ( ) }
< / s e c t i o n >
< section className = "progress" >
< ProgressSlider / >
< span className = "current" > { this . props . time _position ? < Dater type = "length" data = { this . props . time _position } / > : '-' } < / s p a n >
< span className = "total" > { this . props . current _track ? < Dater type = "length" data = { this . props . current _track . length } / > : '-' } < / s p a n >
< / s e c t i o n >
< section className = "volume" >
< VolumeControl / >
< / s e c t i o n >
< / d i v >
) ;
}
}
/ * *
* Export our component
*
* We also integrate our global store , using connect ( )
* * /
const mapStateToProps = ( state , ownProps ) => {
return {
current _track : ( typeof ( state . ui . current _track ) !== 'undefined' && typeof ( state . ui . tracks ) !== 'undefined' && typeof ( state . ui . tracks [ state . ui . current _track . uri ] ) !== 'undefined' ? state . ui . tracks [ state . ui . current _track . uri ] : null ) ,
radio _enabled : ( state . ui . radio && state . ui . radio . enabled ? true : false ) ,
play _state : state . mopidy . play _state ,
time _position : state . mopidy . time _position ,
consume : state . mopidy . consume ,
repeat : state . mopidy . repeat ,
random : state . mopidy . random
}
}
const mapDispatchToProps = ( dispatch ) => {
return {
mopidyActions : bindActionCreators ( mopidyActions , dispatch )
}
}
export default connect ( mapStateToProps , mapDispatchToProps ) ( PlaybackControls )