import React, { Component } from 'react' import { connect } from 'react-redux' import actions from 'app/actions' import { isHandheld, xor, timestampToSeconds } from 'app/utils' import ParagraphList from 'app/views/editor/paragraph/components/paragraph.list' import { inlineComponents } from './components.inline' class PlayerTranscript extends Component { constructor(props){ super(props) this.handleAnnotationClick = this.handleAnnotationClick.bind(this) this.handleParagraphDoubleClick = this.handleParagraphDoubleClick.bind(this) this.handleScroll = this.handleScroll.bind(this) this.containerRef = React.createRef() } componentDidUpdate(prevProps) { if (this.props.section !== prevProps.section) { this.containerRef.current.scrollTo(0, 0) setTimeout(() => { this.containerRef.current.scrollTo(0, 0) }, 20) } if ( this.props.currentSection.index === 0 && this.props.isFullscreen && this.props.isFullscreen !== prevProps.isFullscreen ) { console.log('fullscreen started for the first time') this.scrollToTopOfSection() } } scrollToTopOfSection() { const { current } = this.containerRef console.log('scrollToTopOfSection', current) if (!current) return const heading = current.querySelector('.section_heading') let offset = heading ? heading.offsetTop : 0 console.log(heading, offset) if (offset) { current.scrollTo(0, offset) } } handleAnnotationClick(e, paragraph, annotation) { // console.log(annotation) if (annotation.type === 'footnote') { return actions.viewer.openFootnote(annotation) } if (annotation.settings.override_start_ts) { const ts = timestampToSeconds(annotation.settings.override_start_ts) if (ts) { actions.audio.seek(ts) } } else { actions.audio.seek(annotation.start_ts) } actions.audio.play() } handleParagraphDoubleClick(e, paragraph) { } handleScroll(e) { const { viewer } = this.props if (isHandheld) { const isScrolledPastIntro = this.containerRef.current.scrollTop > 100 if (xor(viewer.navGradient, isScrolledPastIntro)) { // console.log('toggle nav gradient', isScrolledPastIntro) actions.viewer.toggleNavGradient(isScrolledPastIntro) } } if (viewer.growlOpen && !viewer.atEndOfSection) { actions.viewer.closeGrowl() if (viewer.currentSection.index === 0) { actions.audio.play() } } } render() { const { paragraphs, color, inlineParagraphCount } = this.props.currentSection const className = "player-transcript " + color + " " + ( inlineParagraphCount > 2 ? 'scrollable' : 'not-scrollable' ) // console.log(this.props.section) return (