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
|
import React, { Component } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import actions from '../../../../actions'
import { ZOOM_STEPS, INNER_HEIGHT } from '../../constants'
import { clamp } from '../../../../util'
import { positionToTime, timeToPosition } from '../../align.util'
import { AnnotationElementLookup } from './annotation.types'
class AnnotationIndex extends Component {
state = {
items: [],
}
constructor(props){
super(props)
this.handleClick = this.handleClick.bind(this)
}
componentDidUpdate(prevProps) {
if (this.props.index.loading) return
if (prevProps.timeline !== this.props.timeline || prevProps.index !== this.props.index) {
this.update()
}
}
update() {
let { timeline, index } = this.props
let { start_ts, zoom, duration } = this.props.timeline
const { order, lookup } = index
let secondsPerPixel = ZOOM_STEPS[zoom] * 0.1 // 0.1 sec / step
let widthTimeDuration = INNER_HEIGHT * secondsPerPixel // secs per pixel
let timeMin = start_ts - 30.0
let timeMax = Math.min(start_ts + widthTimeDuration, duration)
const items = order.filter(id => {
const { start_ts: ts } = lookup[id]
return (timeMin < ts && ts < timeMax)
}).map(id => lookup[id]).reverse()
this.setState({ items })
}
handleClick(e, annotation) {
e.stopPropagation()
if (e.shiftKey) {
e.preventDefault()
this.handleParagraphSelection(annotation)
}
actions.audio.seek(annotation.start_ts)
actions.align.setSelectedAnnotation(annotation.id)
}
handleParagraphSelection(annotation) {
const { selected_paragraph_id } = this.props.timeline
console.log("___________________")
console.log(annotation)
console.log(selected_paragraph_id)
if (!selected_paragraph_id || selected_paragraph_id === -1) {
if (annotation.paragraph_id) {
actions.align.setSelectedParagraph(annotation.paragraph_id)
} else {
actions.paragraph.create({
type: 'paragraph',
start_ts: annotation.start_ts,
}) .then(data => {
console.log(data.res)
actions.align.setSelectedParagraph(data.res.id)
annotation.paragraph_id = data.res.id
actions.annotation.update(annotation)
})
}
} else if (selected_paragraph_id !== annotation.paragraph_id) {
annotation.paragraph_id = selected_paragraph_id
actions.annotation.update(annotation)
}
}
handleDoubleClick(e, annotation) {
e.stopPropagation()
actions.align.showEditAnnotationForm(annotation)
}
render() {
const { timeline, annotationInForm } = this.props
const { start_ts, zoom, selected_annotation_id } = timeline
const { items } = this.state
const className = (zoom < 2)
? 'annotationIndex'
: (zoom < 3)
? 'annotationIndex condensed'
: 'annotationIndex collapsed'
return (
<div className={className}>
{items.map(annotation => {
if (annotationInForm && annotation.id === annotationInForm.id) {
return null
}
const { id, type, start_ts } = annotation
const AnnotationElement = AnnotationElementLookup[type]
const y = timeToPosition(start_ts, timeline)
return (
<AnnotationElement
key={id}
y={y}
selected={annotation.id === selected_annotation_id}
annotation={annotation}
onClick={this.handleClick}
onDoubleClick={this.handleDoubleClick}
/>
)
})}
</div>
)
}
}
const mapStateToProps = state => ({
timeline: state.align.timeline,
annotationInForm: state.align.annotation,
index: state.annotation.index,
})
const mapDispatchToProps = dispatch => ({
})
export default connect(mapStateToProps, mapDispatchToProps)(AnnotationIndex)
|