/** * Custom interactions for Charles Stankievech */ import React, { Component } from 'react' import { connect } from 'react-redux' import { HEADPHONES } from '../constants.js' import { SUBTITLES } from '../subtitles.js' import { isMobile } from 'app/utils' import actions from 'site/actions' import './titles.css' import { history } from "site/store" const HEADPHONES_SHOW_DELAY = 500 const HEADPHONES_HIDE_DELAY = 3000 const TITLE_SHOW_DELAY = 1000 const TITLE_HIDE_DELAY = 6000 const SUBTITLE_HIDE_DELAY = 1000 const FIRST_SUBTITLE_DELAY = 3000 const SUBTITLE_DELAY = 3500 const LAST_SUBTITLE_DELAY = 5000 class TitlesOverlay extends Component { state = { content: null, showText: false, showVideo: false, } constructor(props) { super(props) this.titleRef = React.createRef() this.headphonesRef = React.createRef() this.textRef = React.createRef() this.showTitle = this.showTitle.bind(this) this.showHeadphones = this.showHeadphones.bind(this) this.advance = this.advance.bind(this) } componentDidMount() { if (this.props.interactive) { this.load() } } componentDidUpdate(prevProps) { if ( (this.props.interactive && this.props.interactive !== prevProps.interactive) || this.props.location.pathname !== prevProps.location.pathname ) { this.load() } if ( this.props.popups !== prevProps.popups && this.state.content && this.state.content.popup ) { if (this.props.popups[this.state.content.popup]) { this.setState({ showVideo: true }) } else if (this.state.showVideo) { this.setState({ showText: true }) this.startHeartbeat() } } } load() { const { page_name } = this.props.match.params clearTimeout(this.titleTimeout) this.props.audio.player.stop("text-overlay") if (isMobile) { setTimeout(() => { actions.site.setPopups({ text: true }) }, 100) } if (SUBTITLES[page_name]) { this.setState({ content: SUBTITLES[page_name], showText: false, showVideo: false, }) setTimeout(SUBTITLES[page_name].headphones ? this.showHeadphones : this.showTitle, 0) } else { this.setState({ content: null, showText: false, showVideo: false, }) } } startHeartbeat() { if (this.state.content.audio_url) { this.props.audio.player.stop("text-overlay") this.props.audio.player.playURL({ id: "text-overlay", url: this.state.content.audio_url, }) } } showHeadphones() { if (!this.headphonesRef.current) return this.headphonesTimeout = setTimeout(() => { this.headphonesRef.current.style.opacity = 1 this.headphonesTimeout = setTimeout(() => { this.headphonesRef.current.style.opacity = 0 setTimeout(this.showTitle, TITLE_SHOW_DELAY) }, HEADPHONES_HIDE_DELAY) }, HEADPHONES_SHOW_DELAY) } showTitle(showSubtitle) { if (!this.titleRef.current) return let title; if (showSubtitle) { title = (this.props.language === 'de' && this.state.content.subtitle_de) || this.state.content.subtitle } else { title = (this.props.language === 'en' && this.state.content.subtitle_en) || this.state.content.title } this.titleRef.current.innerHTML = "" this.titleRef.current.style.color = this.state.content.color || "rgba(255, 121, 13, 1.0)" this.titleRef.current.style.opacity = 0 this.titleTimeout = setTimeout(() => { this.titleRef.current.innerHTML = `