Files
Iris/src/js/components/PlaybackControls.js

152 lines
5.5 KiB
JavaScript
Raw Normal View History

import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
2017-06-16 15:40:39 +12:00
import { Link } from 'react-router'
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-22 09:22:10 +12:00
import * as uiActions from '../services/ui/actions'
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
}
}
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>
}
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</span></a>
2017-10-10 13:05:28 +13:00
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</span></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</span></a>
2017-10-10 13:05:28 +13:00
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</span></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</span></a>
2017-10-10 13:05:28 +13:00
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</span></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
}
render(){
2017-07-15 23:49:17 +12:00
var images = false
if (this.props.current_track && this.props.current_track.images){
images = this.props.current_track.images
}
return (
2017-06-22 08:59:40 +12:00
<div className={(this.state.expanded ? "expanded playback-controls" : "playback-controls")}>
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} />
</div>
<div className="title">
{ this.props.current_track ? this.props.current_track.name : <span>-</span> }
</div>
<div className="artist">
2017-07-26 15:24:18 +12:00
{ this.props.current_track ? <ArtistSentence artists={ this.props.current_track.artists } /> : <ArtistSentence /> }
</div>
2017-07-26 15:24:18 +12:00
</div>
<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" />
</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" />
</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" />
</a>
</section>
<section className="settings">
{ this.renderConsumeButton() }
{ this.renderRandomButton() }
{ this.renderRepeatButton() }
</section>
<section className="progress">
<ProgressSlider />
<span className="current">{ this.props.time_position ? <Dater type="length" data={this.props.time_position} /> : '-' }</span>
<span className="total">{ this.props.current_track ? <Dater type="length" data={this.props.current_track.length} /> : '-' }</span>
</section>
<section className="volume">
<VolumeControl />
</section>
2017-06-22 08:59:40 +12:00
<section className="triggers">
<a className="control next" onClick={() => this.setState({expanded: !this.state.expanded})}>
{this.state.expanded ? <FontAwesome name="chevron-down" /> : <FontAwesome name="chevron-up" />}
</a>
</section>
</div>
);
}
}
/**
* Export our component
*
* We also integrate our global store, using connect()
**/
const mapStateToProps = (state, ownProps) => {
return {
current_track: (state.core.current_track !== undefined && state.core.tracks !== undefined && state.core.tracks[state.core.current_track.uri] !== undefined ? state.core.tracks[state.core.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 {
2017-06-22 09:22:10 +12:00
uiActions: bindActionCreators(uiActions, dispatch),
mopidyActions: bindActionCreators(mopidyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(PlaybackControls)