import React, { Component } from 'react' import { connect } from 'react-redux' import actions from 'app/actions' import { ROMAN_NUMERALS, SECTION_LIMITED_MESSAGE } from 'app/constants' import { timestamp } from 'app/utils' import { thumbnailURL, sectionProgressPercentage } from 'app/utils/annotation.utils' import { SpeakerIcon } from '../nav/viewer.icons' const SECTION_WIDTH = 13 * 16 class ViewerSectionsList extends Component { state = { selectedSectionIndex: -1, } constructor(props) { super(props) this.scrollRef = React.createRef() this.handleWheel = this.handleWheel.bind(this) } shouldComponentUpdate(nextProps) { if (this.props.currentSection !== nextProps.currentSection) { this.scrollToSection(nextProps.currentSection) } if (nextProps.nav !== this.props.nav) return true return nextProps.nav } scrollToSection(section) { const dx = section.index * SECTION_WIDTH clearTimeout(this.timeout) this.timeout = setTimeout(() => { this.scrollRef.current.scrollTo(dx, 0) }, 500) } handleWheel(e) { let delta = Math.abs(e.deltaY) > Math.abs(e.deltaX) ? e.deltaY : e.deltaX this.scrollRef.current.scrollLeft += delta } handleSectionClick(e, section) { if (this.props.onlyEnableFirstSection && section.index !== 0) { this.setState({ selectedSectionIndex: section.index }) clearTimeout(this.warningFadeTimeout) this.warningFadeTimeout = setTimeout(() => { this.setState({ selectedSectionIndex: -1 }) }, 10000) } else { actions.viewer.seekToSection(section) } } render() { const { play_ts, sections, media, currentSection, onlyEnableFirstSection } = this.props const { selectedSectionIndex } = this.state return (