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
|
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 { ZOOM_STEPS } from '../../constants'
import { clamp } from '../../../../util'
import { timeToPosition } from '../../align.util'
import { Select } from '../../../../common'
const TIMESTAMP_TYPES = ['sentence', 'header'].map(name => ({ name, label: name }))
class AnnotationForm extends Component {
state = {
data: {},
}
constructor(props){
super(props)
this.handleChange = this.handleChange.bind(this)
this.handleSelect = this.handleSelect.bind(this)
}
componentDidMount(){
this.setState({
data: { ...this.props.annotation },
})
}
componentDidUpdate(prevProps){
if (this.props.annotation !== prevProps.annotation) {
this.setState({
data: { ...this.props.annotation },
})
}
}
handleChange(e) {
const { name, value } = e.target
this.handleSelect(name, value)
}
handleSelect(name, value) {
this.setState({
data: {
...this.state.data,
[name]: value,
}
})
}
render() {
const { timeline } = this.props
const { data } = this.state
if (!data.start_ts) return <div></div>
return (
<div
className='annotationForm'
style={{
top: timeToPosition(data.start_ts, timeline),
}}
>
{data.type === 'sentence' && this.renderTextarea()}
{data.type === 'heading' && this.renderTextarea()}
<div className='row'>
<Select
name='type'
selected={data.type}
options={TIMESTAMP_TYPES}
defaultOption='text'
onChange={this.handleSelect}
/>
<button>Save</button>
</div>
</div>
)
}
renderTextarea() {
return (
<div>
<textarea
value={data.text}
onChange={this.handleChange}
/>
</div>
)
}
}
/*
- get the first sentence from the text
- display the form at that point
*/
const mapStateToProps = state => ({
annotation: state.align.annotation,
timeline: state.align.timeline,
})
const mapDispatchToProps = dispatch => ({
})
export default connect(mapStateToProps, mapDispatchToProps)(AnnotationForm)
|