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
|
import React, { Component } from 'react'
import { connect } from 'react-redux'
import './jakrawal.links.css'
import { history } from "site/store"
const RESET_STATE = {
left: null,
right: null,
vertical: false,
curtain: false,
lateralLink: null,
verticalLink: 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,
curtain: true,
verticalLink: "home",
})
clearTimeout(this.timeout)
this.timeout = setTimeout(() => {
this.setState({ vertical: true })
}, VERTICAL_TIMEOUT)
return
}
const partz = page_partz[1].split("")
const isOnA = partz[0] === 'a';
const lateralLink = (isOnA ? 'b' : 'a') + partz[1]
const verticalLink = lateralLink === 'a8' ? "home" : partz[0] + (parseInt(partz[1]) + 1)
this.setState({
left: !isOnA,
right: isOnA,
lateralLink,
verticalLink,
curtain: true,
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(`/thelastmuseum/nilthamrong-${this.state.lateralLink}`)
}
goVertical() {
this.setState({ vertical: false })
if (this.state.verticalLink === 'home') {
history.push(`/thelastmuseum/home`)
} else {
history.push(`/thelastmuseum/nilthamrong-${this.state.verticalLink}`)
}
}
render() {
const { left, right, vertical, curtain } = this.state
if (!this.props.interactive || (!left && !right && !vertical && !curtain)) 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)
|