import React, { Component } from 'react' import { connect } from 'react-redux' import { TransitionGroup, CSSTransition } from 'react-transition-group' import actions from 'app/actions' import { floatInRange, floatLT } from 'app/utils' import { fullscreenComponents } from './components.fullscreen' class PlayerFullscreen extends Component { state = { elements: [], } componentDidMount() { this.setCurrentElements() } componentDidUpdate(prevProps) { if (this.props.audio.play_ts === prevProps.audio.play_ts) return this.setCurrentElements() } setCurrentElements() { const { audio, timeline, currentSection } = this.props const { play_ts } = audio const elements = timeline.filter(element => ( floatInRange(element.start_ts, play_ts, element.fade_out_start_ts + 0.1) )) // console.log(elements) if (elements.length) { const lastElement = elements[elements.length - 1] if (lastElement.color && lastElement.color.textColor === '#ffffff') { actions.viewer.setNavStyle('black') } else { actions.viewer.setNavStyle('white') } } else { actions.viewer.setNavStyle(currentSection.color) } this.setState({ elements }) } render() { const { audio, media } = this.props const { play_ts } = audio const { elements } = this.state const className = elements.length ? "viewer-fullscreen active" : "viewer-fullscreen" // console.log(elements, play_ts) return (
{elements.map(element => { if (!(element.type in fullscreenComponents)) { return null } let { type, index, fadeInDuration, fadeOutDuration, start_ts, end_ts, fade_in_end_ts, fade_out_start_ts, } = element const isEntering = floatInRange(start_ts, play_ts, fade_in_end_ts) const isLeaving = floatInRange(fade_out_start_ts, play_ts, end_ts) const FullscreenComponent = fullscreenComponents[type] fadeInDuration *= 1000 fadeOutDuration *= 1000 if (!isEntering && !isLeaving) { fadeInDuration = 0 fadeOutDuration = 0 } const transitionDuration = (isEntering ? fadeInDuration : fadeOutDuration) + 'ms' // console.log(play_ts, isEntering, isLeaving, fadeInDuration, fadeOutDuration) return ( ) })}
) } } const FirstChild = (props) => { const childrenArray = React.Children.toArray(props.children); return childrenArray[0] || null; } const mapStateToProps = state => ({ currentSection: state.viewer.currentSection, audio: state.audio, media: state.media.index, timeline: state.viewer.currentSection ? state.viewer.currentSection.fullscreenTimeline : [], }) export default connect(mapStateToProps)(PlayerFullscreen)