2017-06-16 09:37:40 +12:00
import React , { PropTypes } from 'react'
import { connect } from 'react-redux'
2017-06-16 15:40:39 +12:00
import { Link } from 'react-router'
2017-06-16 09:37:40 +12:00
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'
2017-07-25 16:33:31 +12:00
import Icon from './Icon'
2017-06-16 09:37:40 +12:00
2017-06-22 09:22:10 +12:00
import * as uiActions from '../services/ui/actions'
2017-06-16 09:37:40 +12:00
import * as mopidyActions from '../services/mopidy/actions'
class PlaybackControls extends React . Component {
2017-10-10 13:05:28 +13:00
constructor ( props ) {
2017-06-22 08:59:40 +12:00
super ( props )
this . state = {
expanded : false
}
2017-06-16 09:37:40 +12:00
}
renderPlayButton ( ) {
2017-07-25 16:33:31 +12:00
var button = < a className = "control play" onClick = { ( ) => this . props . mopidyActions . play ( ) } > < Icon name = "play" / > < / a >
2017-10-10 13:05:28 +13:00
if ( this . props . play _state == 'playing' ) {
2017-07-25 16:33:31 +12:00
button = < a className = "control play" onClick = { ( ) => this . props . mopidyActions . pause ( ) } > < Icon name = "pause" / > < / a >
2017-06-16 09:37:40 +12:00
}
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 >
2017-10-10 13:05:28 +13:00
if ( this . props . consume ) {
2017-06-16 09:37:40 +12:00
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 >
2017-10-10 13:05:28 +13:00
if ( this . props . random ) {
2017-06-16 09:37:40 +12:00
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 >
2017-10-10 13:05:28 +13:00
if ( this . props . repeat ) {
2017-06-16 09:37:40 +12:00
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 ;
}
2017-06-22 09:22:10 +12:00
handleThumbnailClick ( e ) {
e . preventDefault ( ) ;
2017-10-09 21:08:27 +13:00
this . props . uiActions . openModal ( 'kiosk_mode' ) ;
2017-06-22 09:22:10 +12:00
}
2017-06-16 09:37:40 +12:00
render ( ) {
2017-07-15 23:49:17 +12:00
var images = false
2017-08-03 15:26:54 +12:00
if ( this . props . current _track && this . props . current _track . images ) {
images = this . props . current _track . images
2017-06-16 09:37:40 +12:00
}
return (
2017-06-22 08:59:40 +12:00
< div className = { ( this . state . expanded ? "expanded playback-controls" : "playback-controls" ) } >
2017-06-16 09:37:40 +12:00
2017-07-26 15:24:18 +12:00
< div className = "current-track" >
2017-06-22 09:22:10 +12:00
< div className = "thumbnail-wrapper" onClick = { e => this . handleThumbnailClick ( e ) } >
< Thumbnail size = "small" images = { images } / >
< / d i v >
2017-06-16 09:37:40 +12:00
< div className = "title" >
{ this . props . current _track ? this . props . current _track . name : < span > - < / s p a n > }
< / d i v >
< div className = "artist" >
2017-07-26 15:24:18 +12:00
{ this . props . current _track ? < ArtistSentence artists = { this . props . current _track . artists } / > : < ArtistSentence / > }
2017-06-16 09:37:40 +12:00
< / d i v >
2017-07-26 15:24:18 +12:00
< / d i v >
2017-06-16 09:37:40 +12:00
< section className = "playback" >
2017-06-22 08:59:40 +12:00
< a className = "control previous" onClick = { ( ) => this . props . mopidyActions . previous ( ) } >
2017-07-25 16:33:31 +12:00
< Icon name = "back" / >
2017-06-16 09:37:40 +12:00
< / a >
{ this . renderPlayButton ( ) }
2017-06-22 08:59:40 +12:00
< a className = "control stop" onClick = { ( ) => this . props . mopidyActions . stop ( ) } >
2017-07-25 16:33:31 +12:00
< Icon name = "stop" / >
2017-06-16 09:37:40 +12:00
< / a >
2017-06-22 08:59:40 +12:00
< a className = "control next" onClick = { ( ) => this . props . mopidyActions . next ( ) } >
2017-07-25 16:33:31 +12:00
< Icon name = "skip" / >
2017-06-16 09:37:40 +12:00
< / a >
< / s e c t i o n >
< section className = "settings" >
2017-10-21 18:45:55 +13:00
{ this . renderConsumeButton ( ) }
{ this . renderRandomButton ( ) }
{ this . renderRepeatButton ( ) }
2017-06-16 09:37:40 +12:00
< / 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 >
2017-06-22 08:59:40 +12:00
< section className = "triggers" >
2017-10-21 18:45:55 +13:00
< a className = "control expanded-controls" onClick = { ( ) => this . setState ( { expanded : ! this . state . expanded } ) } >
2017-06-22 08:59:40 +12:00
{ this . state . expanded ? < FontAwesome name = "chevron-down" / > : < FontAwesome name = "chevron-up" / > }
< / a >
2017-10-21 18:45:55 +13:00
< a className = { "control sidebar-toggle" + ( this . props . sidebar _open ? ' open' : '' ) } onClick = { ( ) => this . props . uiActions . toggleSidebar ( ) } >
< FontAwesome className = "open" name = "bars" / >
< / a >
2017-06-22 08:59:40 +12:00
< / s e c t i o n >
2017-06-16 09:37:40 +12:00
< / d i v >
) ;
}
}
/ * *
* Export our component
*
* We also integrate our global store , using connect ( )
* * /
const mapStateToProps = ( state , ownProps ) => {
return {
2017-11-10 15:56:01 +13:00
current _track : ( state . core . tracks [ state . core . current _track _uri ] !== undefined ? state . core . tracks [ state . core . current _track _uri ] : null ) ,
2017-06-16 09:37:40 +12:00
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 ,
2017-10-21 18:45:55 +13:00
random : state . mopidy . random ,
sidebar _open : state . ui . sidebar _open
2017-06-16 09:37:40 +12:00
}
}
const mapDispatchToProps = ( dispatch ) => {
return {
2017-06-22 09:22:10 +12:00
uiActions : bindActionCreators ( uiActions , dispatch ) ,
2017-06-16 09:37:40 +12:00
mopidyActions : bindActionCreators ( mopidyActions , dispatch )
}
}
export default connect ( mapStateToProps , mapDispatchToProps ) ( PlaybackControls )