summaryrefslogtreecommitdiff
path: root/frontend/site/projects/museum/views/jakrawal.links.js
blob: 92e3b0edc3e899aa94cd52d901ec0cd36670aa8a (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
import React, { Component } from 'react'
import { connect } from 'react-redux'

import './jakrawal.links.css'

import { history } from "site/store"

const JAKRAWAL_TEXTS = [
  "<i>Wildfires</i> occur frequently during the dry season in northern Thailand’s high mountains. The source of fire is not natural but arson.",
  "In the past it was hypothesized that local people set the fires to clear land for agricultural use, or for hunting.",
  "There were efforts to solve the problem at the community level, but the fires only became more severe.",
  "Strangely, the blazes often occurred in the national park—an area difficult for villagers to access.",
  "During the wildfire suppression efforts of May 2020, a group of scholars and volunteers discovered important evidence that would change the original hypothesis.",
  "They found several instances of improvised devices made of clothes pegs connected to a small battery by a power cable.",
  "Combustion was triggered by a small clod of clay positioned in the middle between the pegs, acting as a timer. After melting in the heat the wires attached to the batteries would ignite.",
  "Villagers who were interviewed said that this was not a technique that they were familiar with.",
  "Although we cannot know the intention of the burners, it is likely that the park’s natural resources are being used to benefit some group of people. And the poor have always been condemned.",
]

const RESET_STATE = {
  left: null,
  right: null,
  vertical: false,
  lateralLink: null,
  verticalLink: null,
  text: null,
  hovering: false,
}

const VERTICAL_TIMEOUT = 10000
const AUTOADVANCE_TIMEOUT = 40000

class JakrawalLinks extends Component {
  state = {
    ...RESET_STATE
  }

  constructor(props) {
    super(props)
    this.goLateral = this.goLateral.bind(this)
    this.goVertical = this.goVertical.bind(this)
    this.handleEnter = this.handleEnter.bind(this)
    this.handleLeave = this.handleLeave.bind(this)
  }

  componentDidMount() {
    if (this.props.interactive) {
      this.load()
    }
  }

  componentDidUpdate(prevProps) {
    if (
      (this.props.interactive && this.props.interactive !== prevProps.interactive)
      || this.props.location.pathname !== prevProps.location.pathname
    ) {
      this.load(prevProps.match && prevProps.match.params)
    }
  }

  load(lastParams) {
    const { page_name } = this.props.match.params
    const page_partz = page_name.split("-")
    const isJakrawal = page_partz[0] === 'nilthamrong'

    if (!isJakrawal || page_partz[1] === 'home') {
      clearTimeout(this.autoadvanceTimeout)
      clearTimeout(this.timeout)
      this.setState({
        ...RESET_STATE,
      })
      return      
    }
    if (page_partz[1] === 'a9') {
      clearTimeout(this.autoadvanceTimeout)
      clearTimeout(this.timeout)
      this.autoadvanceTimeout = setTimeout(this.goVertical, AUTOADVANCE_TIMEOUT)
      this.setState({
        ...RESET_STATE,
        verticalLink: "home",
      })
      return
    }
    const partz = page_partz[1].split("")
    const isOnA = partz[0] === 'a';
    const lateralLink = (isOnA ? 'b' : 'a') + partz[1]
    const verticalLink = partz[0] + (parseInt(partz[1]) + 1)
    const text = JAKRAWAL_TEXTS[parseInt(partz[1]) - 1]
    this.setState({
      left: !isOnA,
      right: isOnA,
      lateralLink,
      verticalLink,
      text,
      hovering: false,
    })
    if (!lastParams || lastParams.page_name !== ('nilthamrong' + lateralLink)) {
      clearTimeout(this.autoadvanceTimeout)
      this.autoadvanceTimeout = setTimeout(this.goVertical, AUTOADVANCE_TIMEOUT)
      clearTimeout(this.timeout)
      this.timeout = setTimeout(() => {
        this.setState({ vertical: true })
      }, VERTICAL_TIMEOUT)
    }
  }

  handleEnter() {
    this.setState({ hovering: true })
  }
  handleLeave() {
    this.setState({ hovering: false })
  }
  goLateral() {
    history.push(`/last-museum/nilthamrong-${this.state.lateralLink}/`)
  }
  goVertical() {
    history.push(`/last-museum/nilthamrong-${this.state.verticalLink}/`)
  }

  render() {
    const { left, right, vertical } = this.state
    if (!this.props.interactive || (!left && !right && !vertical)) return null
    return (
      <div>
        <div className="jakrawal-curtain" />
        {vertical && <div className="jakrawal-full" onClick={this.goVertical} />}
        {left && <div className="jakrawal-left" onClick={this.goLateral} />}
        {right && <div className="jakrawal-right" onClick={this.goLateral} />}
      </div>
    )
  }
}

const mapStateToProps = state => ({
  interactive: state.site.interactive,
})

export default connect(mapStateToProps)(JakrawalLinks)

/*
  {text && <div className={hovering ? "jakrawal-text hovering" : "jakrawal-text"} dangerouslySetInnerHTML={{ __html: text }}></div>}
  {text && <div className="jakrawal-text-icon" onMouseEnter={this.handleEnter} onMouseLeave={this.handleLeave}><img src="/last-museum/static/uploads/3/cursor/The_Last_Museum_-_Symbols-103.png"/></div>}
 */