summaryrefslogtreecommitdiff
path: root/frontend/site/projects/museum/views/flash.js
blob: bb7a717f5cef37f90be3699298a301772093a3e5 (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
/**
 * An orange flash when navigating from page to page
 */

import React, { Component } from 'react'

import "./flash.css"

import { ARTISTS } from "site/projects/museum/constants"

export default class Flash extends Component {
  constructor(props) {
    super(props)
    this.state = {
      flashing: false,
      artist_name: "",
    }
  }

  componentDidUpdate(prevProps) {
    if (this.props.location.pathname !== prevProps.location.pathname) {
      this.flash()
    }
  }

  flash() {
    const { page_name } = this.props.match.params
    const artist_name = page_name.split('-')[0]
    if (!(artist_name in ARTISTS)) {
      return
    }
    if (artist_name !== this.state.artist_name) {
      this.setState({ flashing: true, artist_name })
      setTimeout(() => {
        this.setState({ flashing: false })
      }, 100)
    }
  }

  render() {
    if (!this.state.flashing) return null
    return (
      <div className="flash" />
    )
  }
}