summaryrefslogtreecommitdiff
path: root/frontend/site/projects/museum/views/nav.overlay.js
blob: c2bd94bd39071dce8ba4dc618ee2a06dd8af4e9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import React, { Component } from 'react'

import actions from 'site/actions'

import "./nav.css"

import TextOverlay from './text.overlay'
import SubtitlesOverlay from './subtitles.overlay'
import { ARTISTS, ARTIST_ORDER, PROJECT_PAGE_SET } from "site/projects/museum/constants"
import { ArrowLeft, ArrowRight } from "site/projects/museum/icons"
import { history } from "site/store"

import Counter from './counter'

export default class NavOverlay extends Component {
  state = {
    showHome: false,
    showFooter: false,
    showArtist: false,
    showCounter: 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)
  }

  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,
        showFooter: false,
        showArtist: false,
        showCounter: false,
        currentArtist: null,
        artist: {},
      })
    }
    else if (pathkey === 'home') {
      this.setState({
        showHome: false,
        showFooter: true,
        showArtist: false,
        showCounter: false,
        currentArtist: null,
        artist: {},
      })
    }
    else if (PROJECT_PAGE_SET.has(pathkey)) {
      this.setState({
        showHome: true,
        showFooter: false,
        showArtist: false,
        showCounter: false,
      })
    }
    else if (pathkey in ARTISTS) {
      const shouldShowFooter = this.state.currentArtist !== pathkey
      this.setState({
        showHome: true,
        showFooter: true,
        showArtist: true,
        showCounter: pathkey === 'nilthamrong' && path_chapter !== "home",
        currentArtist: pathkey,
        artist: ARTISTS[pathkey],
      }, () => shouldShowFooter && this.quicklyShowFooter())
    } else {
      this.setState({
        showHome: false,
        showFooter: false,
        showCounter: false,
        showArtist: false,
        currentArtist: null,
        artist: {},
      })
    }
  }

  quicklyShowFooter() {
    clearTimeout(this.footerTimeout)
    // this.footerRef.current.classList.add("instant")
    this.footerRef.current.classList.add("visible")
    this.footerTimeout = setTimeout(() => {
      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/`)
  }

  render() {
    const { showArtist, showHome, showCounter, showFooter, artist } = this.state
    return (
      <div className="museum-nav">
        {showHome && (
          <div className="home-link" onClick={this.goHome}>
            Home
          </div>
        )}
        {showCounter && <Counter />}
        <TextOverlay location={this.props.location} match={this.props.match} />
        {showFooter && (
          showArtist ? (
            <div className="footer with-artist" ref={this.footerRef}>
              <div className="footer-gradient" />
              <div className="artist-desc">
                <span className="artist-name">{artist.name}</span>
                <span className="artist-location">{artist.location}</span>
              </div>
              <div className="nav-arrow arrow-left" onClick={this.previousArtist}>{ArrowLeft}</div>
              <div className="nav-arrow arrow-right" onClick={this.nextArtist}>{ArrowRight}</div>
            </div>
          ) : (
            <div className="footer no-artist" ref={this.footerRef} />
          )
        )}
        <SubtitlesOverlay location={this.props.location} match={this.props.match} />
      </div>
    )
  }
}