import React, { Component } from 'react' import { connect } from 'react-redux' import actions from 'app/actions' import { ROMAN_NUMERALS } from 'app/constants' import { Arrow } from './viewer.icons' import NavPlayer from './nav.player' import { thumbnailURL, sectionProgressPercentage } from 'app/utils/annotation.utils' class NavParent extends Component { state = { hoveringNext: false, hoveringNav: false, suppressHover: false, } constructor(props){ super(props) this.handleMouseMove = this.handleMouseMove.bind(this) this.handleMouseEnter = this.handleMouseEnter.bind(this) this.handleMouseLeave = this.handleMouseLeave.bind(this) this.handleMouseEnterNext = this.handleMouseEnterNext.bind(this) this.handleMouseLeaveNext = this.handleMouseLeaveNext.bind(this) this.handleNavBarClick = this.handleNavBarClick.bind(this) this.goToNextSection = this.goToNextSection.bind(this) } handleMouseEnter(){ // console.log('mouse enter') if (this.state.suppressHover) return this.setState({ hoveringNext: false, hoveringNav: true }) } handleMouseEnterNext(){ // console.log('mouse enter next', this.state.suppressHover) if (this.state.suppressHover) return this.setState({ hoveringNext: true, hoveringNav: false }) } handleMouseLeave(){ // console.log('mouse leave') this.setState({ hoveringNav: false }) clearTimeout(this.timeout) this.timeout = setTimeout(() => { this.setState({ hoveringNext: false, suppressHover: false }) }, 100) } handleMouseLeaveNext(){ // console.log('mouse leave next') this.setState({ hoveringNext: false, suppressHover: true, }) clearTimeout(this.timeout) this.timeout = setTimeout(() => { this.setState({ suppressHover: false }) }, 100) } handleNavBarClick(e) { e && e.stopPropagation() actions.viewer.toggleComponent('nav') console.log('>> CLICK NAV') } handleMouseMove(e) { e && e.stopPropagation() } goToNextSection(e) { e && e.preventDefault() e && e.stopPropagation() const { viewer } = this.props console.log('>> SEEK') if (viewer.nextSection) { actions.viewer.seekToSection(viewer.nextSection) } else { actions.viewer.seekToBeginning() } this.setState({ hoveringNext: false, hoveringNav: false, suppressHover: true }) } render() { const { viewer, play_ts, started, playing } = this.props let containerClassName = "viewer-nav " + viewer.navStyle let navClassName = 'nav-row main-nav' if (this.state.hoveringNav || !started) containerClassName += ' hovering-nav' if ((this.state.hoveringNext || (viewer.atEndOfSection && !playing)) && !viewer.nav && viewer.nextSection) containerClassName += ' hovering-next' return (
{viewer.currentSection && ( viewer.mediaTitle ? {viewer.mediaTitle} : {ROMAN_NUMERALS[viewer.currentSection.index]} {'. '} {viewer.currentSection.title} )}
{viewer.nextSection ? "Next" : {'Replay Episode 1. Animist Origins & Export Projections'} }
{viewer.nextSection &&
}
) } } const mapStateToProps = state => ({ viewer: state.viewer, started: state.audio.started, playing: state.audio.playing, play_ts: state.audio.play_ts, }) export default connect(mapStateToProps)(NavParent)