import './CineDialog.styl'; import React, { PureComponent } from 'react'; import { withTranslation } from '../../contextProviders'; import { Icon } from './../../elements/Icon'; import PropTypes from 'prop-types'; class CineDialog extends PureComponent { constructor(props) { super(props); this.state = { cineFrameRate: props.cineFrameRate, isPlaying: props.isPlaying, }; } static propTypes = { /** Minimum value for range slider */ cineMinFrameRate: PropTypes.number.isRequired, /** Maximum value for range slider */ cineMaxFrameRate: PropTypes.number.isRequired, /** Increment range slider can "step" in either direction. */ cineStepFrameRate: PropTypes.number.isRequired, cineFrameRate: PropTypes.number.isRequired, /** 'True' if playing, 'False' if paused. */ isPlaying: PropTypes.bool.isRequired, onPlayPauseChanged: PropTypes.func, onFrameRateChanged: PropTypes.func, onClickNextButton: PropTypes.func, onClickBackButton: PropTypes.func, onClickSkipToStart: PropTypes.func, onClickSkipToEnd: PropTypes.func, /** i18next translation function */ t: PropTypes.func.isRequired, }; static defaultProps = { cineMinFrameRate: 1, cineMaxFrameRate: 90, cineStepFrameRate: 1, cineFrameRate: 24, isPlaying: false, }; componentDidUpdate(prevProps) { // TODO: Not sure if we should just switch this to a stateless // fully-controlled component instead if ( this.props.isPlaying !== prevProps.isPlaying || this.props.isPlaying !== this.state.isPlaying ) { this.setState({ isPlaying: this.props.isPlaying, }); } if ( this.props.cineFrameRate !== prevProps.cineFrameRate || this.props.cineFrameRate !== this.state.cineFrameRate ) { this.setState({ cineFrameRate: this.props.cineFrameRate, }); } } handleInputChange = event => { const target = event.target; let value = target.value; if (target.type === 'range') { value = parseFloat(target.value); } const name = target.name; this.setState({ [name]: value, }); if (name === 'cineFrameRate' && this.props.onFrameRateChanged) { this.props.onFrameRateChanged(parseFloat(value)); } }; onClickPlayPause = () => { const value = !this.state.isPlaying; this.setState({ isPlaying: value, }); if (this.props.onPlayPauseChanged) { this.props.onPlayPauseChanged(value); } }; onClickNextButton = event => { if (this.props.onClickNextButton) { this.props.onClickNextButton(event); } }; onClickBackButton = event => { if (this.props.onClickBackButton) { this.props.onClickBackButton(event); } }; onClickSkipToStart = event => { if (this.props.onClickSkipToStart) { this.props.onClickSkipToStart(event); } }; onClickSkipToEnd = event => { if (this.props.onClickSkipToEnd) { this.props.onClickSkipToEnd(event); } }; render() { const { t } = this.props; return (