blob: 5e07c0bf2bb72ee33e758b889e7cbd32f25d47ab (
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
|
import React, { Component } from 'react'
// import { Link } from 'react-router-dom'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import actions from '../../../actions'
// import * as alignActions from '../align.actions'
import Waveform from './waveform.component'
import Ticks from './ticks.component'
import { ZOOM_STEPS } from '../constants'
import { clamp } from '../../../util'
class Timeline extends Component {
constructor(props){
super(props)
this.handleKeydown = this.handleKeydown.bind(this)
this.handleWheel = this.handleWheel.bind(this)
}
componentDidMount() {
this.bind()
}
componentWillUnmount() {
this.unbind()
}
bind() {
document.addEventListener('keydown', this.handleKeydown)
}
unbind() {
document.removeEventListener('keydown', this.handleKeydown)
}
handleKeydown(e) {
if (e.shiftKey && e.keyCode === 189) {
actions.align.setZoom(this.props.timeline.zoom - 1)
} else if (e.shiftKey && e.keyCode === 187) {
actions.align.setZoom(this.props.timeline.zoom + 1)
}
}
handleWheel(e) {
let { start_ts, zoom, duration } = this.props.timeline
let secondsPerPixel = ZOOM_STEPS[zoom] / 10 // 0.1 sec / step
let widthTimeDuration = window.innerWidth * secondsPerPixel // secs per pixel
start_ts = clamp(start_ts + e.deltaY * ZOOM_STEPS[zoom], 0, duration - widthTimeDuration / 2)
actions.align.setScrollPosition(start_ts)
}
render() {
return (
<div className='timeline' onWheel={this.handleWheel}>
<Waveform />
<Ticks timeline={this.props.timeline} />
</div>
)
}
}
const mapStateToProps = state => ({
timeline: state.align.timeline,
})
const mapDispatchToProps = dispatch => ({
// alignActions: bindActionCreators({ ...alignActions }, dispatch),
})
export default connect(mapStateToProps, mapDispatchToProps)(Timeline)
|