import React, { Component } from 'react' import { connect } from 'react-redux' import actions from 'app/actions' import { GROWL } from 'app/constants' import { floatInRange, clamp } from 'app/utils' import PlayerTranscript from './player.transcript' import PlayerFullscreen from './player.fullscreen' class PlayerContainer extends Component { constructor(props) { super(props) this.handleKeyDown = this.handleKeyDown.bind(this) } componentDidMount() { // console.log(this.props.sections) const { sections } = this.props actions.viewer.setCurrentSection(sections[0], sections[1]) document.addEventListener('keydown', this.handleKeyDown) } componentWillUnmount() { document.removeEventListener('keydown', this.handleKeyDown) } handleKeyDown(e) { if (document.activeElement !== document.body) { return } const { currentSection, audio, viewer } = this.props const { play_ts } = audio let start_ts = 0 let end_ts = 0 if (currentSection) { start_ts = currentSection.start_ts end_ts = currentSection.end_ts } // console.log(e.keyCode) switch (e.keyCode) { case 32: // spacebar e.preventDefault() actions.audio.toggle() break case 37: // left case 38: // up e.preventDefault() if (viewer.vitrineModal.open) { actions.viewer.vitrineGo(-1) } else { actions.audio.seek(clamp(play_ts - 5.0, start_ts, end_ts)) } break case 39: // right case 40: // down e.preventDefault() if (viewer.vitrineModal.open) { actions.viewer.vitrineGo(+1) } else { actions.audio.seek(clamp(play_ts + 5.0, start_ts, end_ts)) } break } } componentDidUpdate(prevProps) { if (this.props.audio.play_ts === prevProps.audio.play_ts) return this.setCurrentSection() } setCurrentSection() { const { audio, currentSection, autoAdvance } = this.props const { play_ts } = audio if (floatInRange(currentSection.start_ts, play_ts, currentSection.end_ts)) { return } if (autoAdvance) { actions.viewer.setSectionFromTimestamp(play_ts) } else { actions.viewer.reachedEndOfSection(currentSection) } } render() { // const { } = this.props const { currentSection } = this.props if (!currentSection) { return
} // console.log(currentSection) return (
) } } const mapStateToProps = state => ({ viewer: state.viewer, audio: state.audio, sections: state.viewer.sections, currentSection: state.viewer.currentSection, autoAdvance: state.viewer.autoAdvance, }) export default connect(mapStateToProps)(PlayerContainer)