From a20da98081b91bcdb8d02c68edf6fcccf8fb046a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 16 Apr 2021 21:33:09 +0200 Subject: basic jakrawal --- .../site/projects/museum/views/jakrawal.links.js | 130 +++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 frontend/site/projects/museum/views/jakrawal.links.js (limited to 'frontend/site/projects/museum/views/jakrawal.links.js') diff --git a/frontend/site/projects/museum/views/jakrawal.links.js b/frontend/site/projects/museum/views/jakrawal.links.js new file mode 100644 index 0000000..880d0e6 --- /dev/null +++ b/frontend/site/projects/museum/views/jakrawal.links.js @@ -0,0 +1,130 @@ +import React, { Component } from 'react' +import { connect } from 'react-redux' + +import './jakrawal.links.css' + +import { history } from "site/store" + +const JAKRAWAL_TEXTS = [ + "Wildfires 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, + lateralLink: null, + verticalLink: null, + text: null, + hovering: false, +} + +const VERTICAL_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.timeout) + this.setState({ + ...RESET_STATE, + }) + return + } + if (page_partz[1] === 'a9') { + clearTimeout(this.timeout) + this.timeout = setTimeout(this.goVertical, VERTICAL_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, + }) + console.log(isOnA, lateralLink, verticalLink) + if (!lastParams || lastParams.page_name !== ('nilthamrong' + lateralLink)) { + clearTimeout(this.timeout) + this.timeout = setTimeout(this.goVertical, 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.lateralLink}/`) + } + + render() { + const { left, right, text, hovering } = this.state + if (!this.props.interactive || !text) return null + return ( +
+ {left &&
} + {right &&
} + {text &&
{text}
} + {text &&
} +
+ ) + } +} + +const mapStateToProps = state => ({ + interactive: state.site.interactive, +}) + +export default connect(mapStateToProps)(JakrawalLinks) -- cgit v1.2.3-70-g09d2