import React, { PropTypes } from 'react' import { connect } from 'react-redux' 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' import Icon from './Icon' import * as uiActions from '../services/ui/actions' import * as mopidyActions from '../services/mopidy/actions' class PlaybackControls extends React.Component{ constructor(props){ super(props) this.state = { expanded: false } } renderPlayButton(){ var button = this.props.mopidyActions.play()}> if (this.props.play_state == 'playing'){ button = this.props.mopidyActions.pause()}> } return button; } renderConsumeButton(){ var button = this.props.mopidyActions.instruct('tracklist.setConsume', [true])}>Consume if (this.props.consume){ button = this.props.mopidyActions.instruct('tracklist.setConsume', [false])}>Consume } return button; } renderRandomButton(){ var button = this.props.mopidyActions.instruct('tracklist.setRandom', [true])}>Shuffle if (this.props.random){ button = this.props.mopidyActions.instruct('tracklist.setRandom', [false])}>Shuffle } return button; } renderRepeatButton(){ var button = this.props.mopidyActions.instruct('tracklist.setRepeat', [true])}>Repeat if (this.props.repeat){ button = this.props.mopidyActions.instruct('tracklist.setRepeat', [false])}>Repeat } return button; } handleThumbnailClick(e){ e.preventDefault(); this.props.uiActions.openModal('kiosk_mode'); } render(){ var images = false if (this.props.current_track && this.props.current_track.images){ images = this.props.current_track.images } return (
this.handleThumbnailClick(e)}>
{ this.props.current_track ? this.props.current_track.name : - }
{ this.props.current_track ? : }
this.props.mopidyActions.previous()}> { this.renderPlayButton() } this.props.mopidyActions.stop()}> this.props.mopidyActions.next()}>
{this.renderConsumeButton()} {this.renderRandomButton()} {this.renderRepeatButton()}
{ this.props.time_position ? : '-' } { this.props.current_track ? : '-' }
this.setState({expanded: !this.state.expanded})}> {this.state.expanded ? : } this.props.uiActions.toggleSidebar()}>
); } } /** * 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, sidebar_open: state.ui.sidebar_open } } const mapDispatchToProps = (dispatch) => { return { uiActions: bindActionCreators(uiActions, dispatch), mopidyActions: bindActionCreators(mopidyActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(PlaybackControls)