import React, { Component } from 'react' import { connect } from 'react-redux' import actions from 'site/actions' import "./nav.css" import "./mobile.css" import TextOverlay from './text.overlay' import JakrawalLinks from './jakrawal.links' import TitlesOverlay from './titles.overlay' import Flash from './flash' import Marquee from './marquee' import LandscapeWarning from './landscape.warning' import { ARTISTS, ARTIST_ORDER, PROJECT_PAGE_SET, BACK_TO_KW } from "site/projects/museum/constants" import { ArrowLeft, ArrowRight } from "site/projects/museum/icons" import MuteButton from "site/audio/mute.button" import { history } from "site/store" import Counter from './counter' class NavOverlay extends Component { state = { showHome: false, showLanguage: false, showFooter: false, showArtist: false, showCounter: false, showMuteButton: false, isProjectPage: false, showClose: false, orangeClose: false, artist: {}, } constructor(props) { super(props) this.footerRef = React.createRef() this.previousArtist = this.previousArtist.bind(this) this.nextArtist = this.nextArtist.bind(this) this.goHome = this.goHome.bind(this) this.changeLanguage = this.changeLanguage.bind(this) } componentDidMount() { this.load() } componentDidUpdate(prevProps) { // console.log(this.props.location.pathname, prevProps.location.pathname) if (this.props.location.pathname !== prevProps.location.pathname) { this.load() } } load() { const { page_name } = this.props.match.params const pathPartz = page_name.split("-") const pathkey = pathPartz[0] const path_chapter = pathPartz[1] // console.log(pathkey) if (pathkey === 'start') { this.setState({ showHome: false, showLanguage: true, showFooter: false, showArtist: false, showCounter: false, currentArtist: null, showMuteButton: false, isProjectPage: false, showClose: true, orangeClose: false, artist: {}, }) } else if (pathkey === 'home') { this.setState({ showHome: false, showLanguage: true, showFooter: true, showArtist: false, showCounter: false, currentArtist: null, showMuteButton: true, isProjectPage: false, showClose: true, orangeClose: true, artist: {}, }) } else if (PROJECT_PAGE_SET.has(pathkey)) { this.setState({ showHome: false, showLanguage: false, showFooter: false, showArtist: false, showCounter: false, showMuteButton: false, isProjectPage: true, showClose: false, orangeClose: false, }) } else if (pathkey in ARTISTS) { const shouldShowFooter = this.state.currentArtist !== pathkey this.setState({ showHome: true, showLanguage: true, showFooter: true, showArtist: true, showMuteButton: true, isProjectPage: false, showClose: false, orangeClose: false, showCounter: pathkey === 'nilthamrong' && path_chapter !== "home", currentArtist: pathkey, artist: ARTISTS[pathkey], }, () => shouldShowFooter && this.quicklyShowFooter()) } else { this.setState({ showHome: false, showLanguage: false, showFooter: false, showCounter: false, showArtist: false, showMuteButton: false, isProjectPage: false, showClose: false, orangeClose: false, currentArtist: null, artist: {}, }) } } quicklyShowFooter() { clearTimeout(this.footerTimeout) // this.footerRef.current.classList.add("instant") this.footerRef.current.classList.add("visible") this.footerTimeout = setTimeout(() => { if (this.footerRef.current) { this.footerRef.current.classList.remove("visible") } }, 5000) } previousArtist() { this.go(-1) } nextArtist() { this.go(1) } go(step) { if (!this.state.currentArtist) return const index = ARTIST_ORDER.indexOf(this.state.currentArtist) const nextIndex = (index + step + ARTIST_ORDER.length) % ARTIST_ORDER.length const currentArtist = ARTIST_ORDER[nextIndex] const artist = ARTISTS[currentArtist] this.setState({ currentArtist, artist }) history.push(`/last-museum/${artist.start}`) } goHome() { history.push(`/last-museum/home/`) } changeLanguage() { actions.site.changeLanguage(this.props.language === "de" ? "en" : "de") } render() { const { language } = this.props const { showArtist, showHome, showLanguage, showMuteButton, showCounter, showFooter, showClose, orangeClose, isProjectPage, artist } = this.state return (
{showCounter && } {showFooter && ( showArtist ? (
{artist.name} {artist.location[language]}
{ArrowLeft}
{ArrowRight}
) : (
) )}
{showHome && (
Home
)} {showLanguage && (
{this.props.language === "de" ? ( de / en ) : ( de / en )}
)} {showMuteButton && ( )}
{showClose && ( {BACK_TO_KW[language]} )} ) } } const mapStateToProps = state => ({ language: state.site.language, }) export default connect(mapStateToProps)(NavOverlay)