import React, { Component } from 'react' import { connect } from 'react-redux' import { Link } from 'react-router-dom' import actions from 'site/actions' import "./nav.css" 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 { isMobile, preloadVideo, preloadImage, preloadAudio } from "app/utils" import LandscapeWarning from './landscape.warning' import TextOverlay from './text.overlay' import JakrawalLinks from './jakrawal.links' import TitlesOverlay from './titles.overlay' import Flash from './flash' import Marquee from './marquee' import Counter from './counter' class NavOverlay extends Component { state = { showHome: false, showLanguage: false, showFooter: false, showArtist: false, showCounter: false, showMuteButton: false, isProjectPage: false, showHomeFooterLinks: false, showClose: false, orangeClose: false, artist: {}, } constructor(props) { super(props) this.preloaded = {} 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) this.preloadNextPages() if (pathkey === 'start') { this.setState({ showHome: false, showLanguage: true, showFooter: false, showArtist: false, showCounter: false, currentArtist: null, showMuteButton: false, isProjectPage: false, showHomeFooterLinks: false, showClose: true, orangeClose: false, artist: {}, }) setTimeout(() => { this.hideRoadblock() }, 10) } else if (pathkey === 'home') { this.setState({ showHome: false, showLanguage: true, showFooter: true, showArtist: false, showCounter: false, currentArtist: null, showMuteButton: true, isProjectPage: false, showHomeFooterLinks: isMobile, 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, showHomeFooterLinks: 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, showHomeFooterLinks: 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, showHomeFooterLinks: false, showClose: false, orangeClose: false, currentArtist: null, artist: {}, }) } } preloadNextPages() { const { page_name } = this.props.match.params const page_path = ["", "thelastmuseum", page_name].join('/') console.log("preload", page_path) console.log(this.props.graph) console.log(this.props.graph.pages[page_path]) const nextPagePaths = this.props.graph.pages[page_path].tiles.reduce((lookup, tile) => { if (tile.href) { lookup[tile.href] = true } return lookup }, {}) Object.keys(nextPagePaths).forEach(nextPagePath => this.preloadNextPage(nextPagePath)) } preloadNextPage(nextPagePath) { const { graph } = this.props const nextPage = graph.pages[nextPagePath] if (!nextPage) return nextPage.tiles.forEach(tile => { if (tile.type === 'video' && !this.preloaded[tile.settings.url]) { this.preloaded[tile.settings.url] = true preloadVideo(tile.settings.url, { canplaythrough: true }) .then(video => { // console.log("preloaded", video.src) // video.src = null }) } else if (tile.type === 'image' && !this.preloaded[tile.settings.url]) { this.preloaded[tile.settings.url] = true preloadImage(tile.settings.url) .then(image => { // console.log("preloaded", image.src) // image.src = null }) } if (tile.settings.custom_cursor_id) { const cursor = graph.uploads.find(upload => upload.id === tile.settings.custom_cursor_id) if (cursor.url && !this.preloaded[cursor.url]) { this.preloaded[cursor.url] = true preloadImage(cursor.url) .then(image => { // console.log("preloaded", image.src) // image.src = null }) } } }) if (nextPage.settings.audio && !this.preloaded[nextPage.settings.audio]) { this.preloaded[nextPage.settings.audio] = true preloadAudio("/thelastmuseum" + nextPage.settings.audio) .then(audio => { // console.log("preloaded", audio.src) // audio.src = null }) } } hideRoadblock() { const roadblock = document.querySelector('.roadblock') if (roadblock) { roadblock.style.display = "none" } } 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(`/thelastmuseum/${artist.start}`) } goHome() { history.push(`/thelastmuseum/home/`) } changeLanguage() { actions.site.changeLanguage(this.props.language === "de" ? "en" : "de") } render() { const { language } = this.props const { showHome, showLanguage, showMuteButton, showFooter, showHomeFooterLinks, showClose, orangeClose, showArtist, isProjectPage, artist, showCounter } = this.state return (