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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
import React, { Component } from 'react'
import { connect } from 'react-redux'
import actions from 'app/actions'
import { ROMAN_NUMERALS } from 'app/constants'
import { isMobile } from 'app/utils'
import { Arrow } from './viewer.icons'
import NavPlayer from './nav.player'
import { thumbnailURL, sectionProgressPercentage, sectionOffsetSeconds } from 'app/utils/annotation.utils'
class NavParent extends Component {
state = {
hoveringNext: false,
hoveringNav: false,
suppressHover: false,
thumbnailMediaURL: "",
}
constructor(props){
super(props)
this.navbarRef = React.createRef()
this.handleMouseMove = this.handleMouseMove.bind(this)
this.handleMouseEnter = this.handleMouseEnter.bind(this)
this.handleMouseLeave = this.handleMouseLeave.bind(this)
this.handleMouseEnterNext = this.handleMouseEnterNext.bind(this)
this.handleMouseLeaveNext = this.handleMouseLeaveNext.bind(this)
this.handleNavBarClick = this.handleNavBarClick.bind(this)
this.handleSectionLinkClick = this.handleSectionLinkClick.bind(this)
this.handleSectionLinkTextClick = this.handleSectionLinkTextClick.bind(this)
this.updateThumbnail = this.updateThumbnail.bind(this)
this.goToNextSection = this.goToNextSection.bind(this)
}
componentDidMount() {
clearTimeout(this.thumbnailLoadTimeout)
this.thumbnailLoadTimeout = setTimeout(this.updateThumbnail, 200)
}
componentDidUpdate(prevProps){
if (prevProps.nextSection !== this.props.nextSection) {
clearTimeout(this.thumbnailLoadTimeout)
this.thumbnailLoadTimeout = setTimeout(this.updateThumbnail, 200)
}
}
updateThumbnail() {
if (this.props.nextSection && this.props.nextSection.media.length) {
this.setState({ thumbnailMediaURL: thumbnailURL(this.props.nextSection.media[0].media) })
}
}
handleMouseEnter(){
// console.log('mouse enter')
if (this.state.suppressHover) return
this.setState({ hoveringNext: false, hoveringNav: true })
}
handleMouseEnterNext(){
// console.log('mouse enter next', this.state.suppressHover)
if (this.state.suppressHover) return
this.setState({ hoveringNext: true, hoveringNav: false })
}
handleMouseLeave(){
// console.log('mouse leave')
this.setState({ hoveringNav: false })
clearTimeout(this.timeout)
this.timeout = setTimeout(() => {
this.setState({ hoveringNext: false, suppressHover: false })
}, 100)
}
handleMouseLeaveNext(){
// console.log('mouse leave next')
this.setState({ hoveringNext: false, suppressHover: true, })
clearTimeout(this.timeout)
this.timeout = setTimeout(() => {
this.setState({ suppressHover: false })
}, 100)
}
handleNavBarClick(e) {
e && e.stopPropagation()
if (isMobile) {
actions.viewer.toggleComponent('nav')
} else {
// console.log('>> CLICK NAV')
// actions.viewer.toggleComponent('nav')
const percent = (e.pageX / this.navbarRef.current.offsetWidth)
const seconds = sectionOffsetSeconds(this.props.currentSection, percent)
console.log(e.pageX, this.navbarRef.current.offsetWidth, percent)
console.log(this.props.currentSection)
console.log(">>", seconds)
actions.viewer.seekToTimestamp(seconds)
}
}
handleSectionLinkClick(e) {
e && e.stopPropagation()
actions.viewer.toggleComponent('nav')
}
handleSectionLinkTextClick(e) {
e && e.stopPropagation()
actions.viewer.toggleComponent('nav')
}
handleMouseMove(e) {
e && e.stopPropagation()
}
goToNextSection(e) {
e && e.preventDefault()
e && e.stopPropagation()
const { viewer } = this.props
// console.log('>> SEEK', viewer.nextSection)
if (viewer.nextSection) {
actions.viewer.seekToSection(viewer.nextSection)
} else {
actions.viewer.showNavComponent('credits')
// actions.viewer.seekToBeginning()
}
this.setState({ hoveringNext: false, hoveringNav: false, suppressHover: true })
}
render() {
const { viewer, currentSection, play_ts, started, playing } = this.props
const { thumbnailMediaURL } = this.state
let containerClassName = "viewer-nav " + viewer.navStyle
let navClassName = 'nav-row main-nav'
if (this.state.hoveringNav || !started) containerClassName += ' hovering-nav'
if ((this.state.hoveringNext || (viewer.atEndOfSection && !playing)) && !viewer.nav && viewer.nextSection) containerClassName += ' hovering-next'
return (
<div ref={this.navbarRef} className={containerClassName} onMouseMove={this.handleMouseMove} onMouseLeave={this.handleMouseLeave}>
<div className={navClassName} onClick={this.handleNavBarClick}>
<div className='nav-section-name' onMouseEnter={this.handleMouseEnter}>
<span className="section-link link" onClick={this.handleSectionLinkTextClick}>
<Arrow type={viewer.nav ? 'down' : 'up'} onClick={this.handleSectionLinkClick} />
{currentSection && (
viewer.mediaTitle
? <span><i>{viewer.mediaTitle}</i></span>
: <span>
{ROMAN_NUMERALS[currentSection.index]}
{'. '}
{currentSection.title}
</span>
)}
</span>
</div>
<div className='nav-player-container' onMouseEnter={this.handleMouseEnter}>
<NavPlayer />
</div>
<div
className='nav-next'
onMouseEnter={this.handleMouseEnter}
>
<span
className="next-link link"
onMouseEnter={this.handleMouseEnterNext}
onClick={this.goToNextSection}
>
{viewer.nextSection
? "Next"
: <span className="replay-link">{'Credits'}</span>
}
<Arrow type={'right'} />
</span>
</div>
<div className="nav-progress-percentage" style={{
width: currentSection ? sectionProgressPercentage(currentSection, play_ts) : 0
}} />
</div>
{viewer.nextSection &&
<div className="next-section-thumbnail"
onClick={this.goToNextSection}
style={{
backgroundImage: (
thumbnailMediaURL && 'url(' + thumbnailMediaURL + ')'
),
}}
/>
}
</div>
)
}
}
const mapStateToProps = state => ({
viewer: state.viewer,
currentSection: state.viewer.currentSection,
nextSection: state.viewer.nextSection,
started: state.audio.started,
playing: state.audio.playing,
play_ts: state.audio.play_ts,
})
export default connect(mapStateToProps)(NavParent)
|