import React, { Component } from 'react' import actions from 'site/actions' import "./nav.css" import { ARTISTS, ARTIST_ORDER } from "site/projects/museum/constants" import { ArrowLeft, ArrowRight } from "site/projects/museum/icons" import { history } from "site/store" export default class NavOverlay extends Component { state = { showHome: false, showFooter: false, showArtist: false, artist: {}, } constructor(props) { super(props) this.previousArtist = this.previousArtist.bind(this) this.nextArtist = this.nextArtist.bind(this) this.goHome = this.goHome.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] // console.log(pathkey) if (pathkey === 'start') { this.setState({ showFooter: true, showArtist: false, currentArtist: null, artist: {}, }) } else if (pathkey in ARTISTS) { this.setState({ showHome: true, showFooter: true, showArtist: true, currentArtist: pathkey, artist: ARTISTS[pathkey], }) } else { this.setState({ showFooter: false, showArtist: false, currentArtist: null, artist: {}, }) } } 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/`) } render() { const { showArtist, showHome, showFooter, artist } = this.state return (
{showHome && (
Home
)} {showFooter && ( showArtist ? (
{artist.name} {artist.location}
{ArrowLeft}
{ArrowRight}
) : (
) )}
) } }