import React, { Component } from 'react' import { connect } from 'react-redux' import { EfluxLogo, EfluxClose, TranscriptIcon } from './eflux.icons' import { PlayButton } from './viewer.icons' import actions from 'app/actions' import { URLS } from 'app/constants' import { isHandheld } from 'app/utils' const PLAY_MESSAGES = { not_started: 'Start the Exhibition', playing: 'Pause', paused: 'Resume', } class EfluxChrome extends Component { state = { eflux: false, play: false, transcript: false, close: false, started: false, playMessage: PLAY_MESSAGES.not_started, } constructor(props) { super(props) this.handleToggle = this.handleToggle.bind(this) this.handleClose = this.handleClose.bind(this) } handleMouseEnter(category) { this.setState({ [category]: true }) } handleMouseLeave(category) { this.setState({ [category]: false }) } handleToggle() { if (this.props.playing) { actions.audio.pause() } else { actions.viewer.playFromClick() } } handleClose() { if (this.props.videoModalOpen) { actions.viewer.closeVideoModal() } else { actions.viewer.toggleFullscreenVisible(false) actions.audio.pause() } this.handleMouseLeave('close') this.handleMouseLeave('eflux') } componentDidUpdate(prevProps) { if (this.props.playing !== prevProps.playing) { if (!this.state.started) { this.setState({ started: true, play: false, }) setTimeout(() => { this.setState({ playMessage: this.props.playing ? PLAY_MESSAGES.playing : PLAY_MESSAGES.paused, }) }, 150) } else { this.setState({ playMessage: this.props.playing ? PLAY_MESSAGES.playing : PLAY_MESSAGES.paused, }) } } else if (prevProps.atEndOfSection !== this.props.atEndOfSection && this.props.atEndOfSection) { // reached end of section if (this.props.currentSection.index === 0) { this.setState({ transcript: true }) } } } render() { const { navStyle, navGradient, playing, transcriptOpen, isFullscreen, fullscreenVisible, isFullscreenSingleton, growlOpen, growlMessage, atEndOfSection, currentSection, videoModalOpen } = this.props let className = "eflux-header" if (navStyle) className += ' ' + navStyle if (navGradient) className += ' gradient' if (transcriptOpen) className += ' transcript-open' if (isFullscreen) className += ' is-fullscreen' // console.log(isFullscreen, fullscreenVisible, isFullscreenSingleton) const fullscreenWantsCloseButton = (isFullscreen && fullscreenVisible && !isFullscreenSingleton) || videoModalOpen return (
this.handleMouseEnter('eflux')} onMouseLeave={() => this.handleMouseLeave('eflux')} > {EfluxLogo}
{growlMessage}
{fullscreenWantsCloseButton && isHandheld && this.renderCloseButton()}
{fullscreenWantsCloseButton && !isHandheld && this.renderCloseButton()} {!videoModalOpen && ( this.handleMouseEnter('play')} onMouseLeave={() => this.handleMouseLeave('play')} > )}
this.handleMouseEnter('transcript')} onMouseLeave={() => this.handleMouseLeave('transcript')} onClick={() => actions.viewer.toggleComponent('transcript')} > {TranscriptIcon}
{'Close fullscreen player'}
{'Back to e-flux'}
{videoModalOpen ? 'Close video' : this.state.playMessage}
actions.viewer.toggleComponent('transcript')} > {'Read the Transcript'}
) } renderCloseButton() { const { videoModalOpen } = this.props return (
this.handleMouseEnter(videoModalOpen ? 'play' : 'close')} onMouseLeave={() => this.handleMouseLeave(videoModalOpen ? 'play' : 'close')} onClick={this.handleClose} > {EfluxClose}
) } } const mapStateToProps = state => ({ navStyle: state.viewer.navStyle, navGradient: state.viewer.navGradient, playing: state.audio.playing, transcriptOpen: state.viewer.transcript, growlOpen: state.viewer.growlOpen, growlMessage: state.viewer.growlMessage, atEndOfSection: state.viewer.atEndOfSection, currentSection: state.viewer.currentSection, isFullscreen: state.viewer.isFullscreen, fullscreenVisible: state.viewer.fullscreenVisible, isFullscreenSingleton: state.viewer.isFullscreenSingleton, videoModalOpen: state.viewer.videoModal.open, }) export default connect(mapStateToProps)(EfluxChrome)