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
|
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { useKeenSlider } from "app/utils/vendor/keen-slider/react"
import "keen-slider/keen-slider.min.css"
import actions from 'app/actions'
import { SpeakerIcon } from 'app/views/viewer/nav/viewer.icons'
import { MediaCitation } from './media.citation'
import { Arrow } from 'app/views/viewer/nav/viewer.icons'
const SPACING = 15
const SLIDES_PER_VIEW = 2
// obnoxious i have to do this but the slideChanged function would be "different" otherwise
let slideChangedHook = slider => console.log(slider)
let slideChanged = slider => slideChangedHook(slider)
const CarouselContainer = ({ element, media, cues, play_ts, withMouseWheel }) => {
const { image_order, caption_lookup } = media.settings
const [currentSlide, setCurrentSlide] = React.useState(0)
const [sliderRef, slider] = useKeenSlider({
slidesPerView: SLIDES_PER_VIEW,
mode: "free",
spacing: SPACING,
centered: true,
loop: false,
slideChanged: slideChanged,
withMouseWheel: withMouseWheel,
})
slideChangedHook = s => {
setCurrentSlide(s.details().relativeSlide)
}
// step thru this carousel's timeline, which is ordered in reverse BTW
if (element) {
element.timeline.some(cue => {
if (cue.start_ts < play_ts && (play_ts - cue.start_ts) < 0.5) {
let slide_index = cue.settings.seek_index
if (currentSlide < slide_index) {
setCurrentSlide(slide_index)
slider.moveToSlideRelative(slide_index)
}
return true
}
return false
})
}
const currentCaption = caption_lookup[image_order[Math.round(currentSlide)]]
return (
<Carousel
media={media}
slider={slider}
sliderRef={sliderRef}
currentSlide={currentSlide}
currentCaption={currentCaption}
cues={cues}
/>
)
}
const CarouselComponent = ({ media, slider, sliderRef, currentSlide, currentCaption, cues }) => {
const { image_order, display_lookup } = media.settings
return (
<div className="carousel-component">
<div className="carousel-positioning">
<div key={'carousel_' + media.id} ref={sliderRef} className='keen-slider carousel-items'>
{image_order.map((id, index) => {
const image = display_lookup[id]
// console.log(image)
return (
<CarouselItem
key={id}
image={image}
slider={slider}
seekAnnotation={cues && cues.lookup[index]}
/>
)
})}
</div>
<CarouselArrow
type="prev"
disabled={!!currentSlide}
onClick={() => {
slider.prev()
}}
/>
<CarouselArrow
type="next"
disabled={currentSlide < image_order.length - 1}
onClick={() => {
slider.next()
}}
/>
</div>
<MediaCitation key={'caption_' + media.id} media={(currentCaption && currentCaption.caption) ? currentCaption : media} />
<div className="carousel-nav" key={'arrows_' + media.id}>
<CarouselDots
currentSlide={currentSlide}
slides={image_order}
onPick={index => {
slider.moveToSlideRelative(index)
}}
/>
</div>
</div>
)
}
const Carousel = React.memo(CarouselComponent)
const CarouselArrow = ({ disabled, type, onClick }) => ((
<div
className={(disabled ? "nav-arrow" : "nav-arrow arrow-disabled") + " " + type}
tabIndex={0}
onClick={e => {
e.stopPropagation()
onClick()
}}
>
<Arrow type={type === 'prev' ? 'left' : 'right'} />
</div>
))
const CarouselDots = ({ slides, currentSlide, onPick }) => ((
<div className="dots">
{[...slides.keys()].map(index => {
return (
<div
key={index}
onClick={() => {
onPick(index)
}}
tabIndex={index}
className={"dot-item" + (Math.round(currentSlide) === index ? " active" : "")}
>
<div className="dot-circle" />
</div>
)
})}
</div>
))
const CarouselItem = ({ image, slider, seekAnnotation }) => {
return (
<div className='keen-slider__slide carousel-item'>
<div className="image-container" style={{ backgroundImage: 'url(' + image.url + ')' }}>
<img
src={image.url}
/>
{seekAnnotation && (
<div
className="speaker-icon"
onClick={() => {
slider.moveToSlideRelative(seekAnnotation.settings.seek_index)
actions.viewer.seekToTimestamp(seekAnnotation.start_ts)
}}
>
{SpeakerIcon}
</div>
)}
</div>
</div>
)
}
const mapStateToProps = state => ({
play_ts: state.audio.play_ts,
})
export default connect(mapStateToProps)(CarouselContainer)
|