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.handleMouseEnter = this.handleMouseEnter.bind(this) this.handleMouseLeave = this.handleMouseLeave.bind(this) this.handleMouseEnterNext = this.handleMouseEnterNext.bind(this) this.handleMouseLeaveNext = this.handleMouseLeaveNext.bind(this) this.goToNextSection = this.goToNextSection.bind(this) } handleMouseEnter(){ if (this.state.suppressHover) return this.setState({ hoveringNext: false, hoveringNav: true }) } handleMouseEnterNext(){ if (this.state.suppressHover) return this.setState({ hoveringNext: true, hoveringNav: false }) } handleMouseLeave(){ this.setState({ hoveringNext: false, hoveringNav: false, suppressHover: false }) } handleMouseLeaveNext(){ this.setState({ hoveringNext: false, suppressHover: true, }) setTimeout(() => { this.setState({ suppressHover: false }) }, 50) } goToNextSection() { const { viewer } = this.props if (viewer.nextSection) { actions.viewer.seekToSection(viewer.nextSection) } else if (viewer.credits) { actions.viewer.seekToBeginning() } else { actions.viewer.showCredits() } } render() { const { viewer, play_ts, started } = 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) && !viewer.nav && !viewer.credits && viewer.nextSection) containerClassName += ' hovering-next' return (
actions.viewer.toggleComponent('nav')}> {viewer.currentSection && ( viewer.mediaTitle ? {viewer.mediaTitle} : {ROMAN_NUMERALS[viewer.currentSection.index]} {'. '} {viewer.currentSection.title} )}
{viewer.credits ? {'Replay Episode 1. Animist Origins & Export Projections'} : "Next" }
{viewer.nextSection &&
{ actions.viewer.seekToSection(viewer.nextSection) this.setState({ hoveringNext: false, hoveringNav: false, suppressHover: true }) }} style={{ backgroundImage: viewer.nextSection.media.length && 'url(' + thumbnailURL(viewer.nextSection.media[0].media) + ')', }}/> }
) } } const mapStateToProps = state => ({ viewer: state.viewer, started: state.audio.started, play_ts: state.audio.play_ts, }) export default connect(mapStateToProps)(NavParent)