summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/paragraph/components/paragraph.list.js
diff options
context:
space:
mode:
Diffstat (limited to 'animism-align/frontend/app/views/paragraph/components/paragraph.list.js')
-rw-r--r--animism-align/frontend/app/views/paragraph/components/paragraph.list.js84
1 files changed, 5 insertions, 79 deletions
diff --git a/animism-align/frontend/app/views/paragraph/components/paragraph.list.js b/animism-align/frontend/app/views/paragraph/components/paragraph.list.js
index e1e7970..3492d7f 100644
--- a/animism-align/frontend/app/views/paragraph/components/paragraph.list.js
+++ b/animism-align/frontend/app/views/paragraph/components/paragraph.list.js
@@ -4,32 +4,23 @@ import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { floatLT, floatLTE } from 'app/utils'
-import actions from 'app/actions'
import ParagraphForm from '../components/paragraph.form'
import { MEDIA_TYPES } from 'app/constants'
class ParagraphList extends Component {
state = {
- paragraphs: [],
currentParagraph: -1,
currentAnnotation: -1,
}
- componentDidMount() {
- this.build()
- }
-
componentDidUpdate(prevProps) {
- if (this.props.paragraph !== prevProps.paragraph) {
- this.build()
- }
if (this.props.audio.play_ts === prevProps.audio.play_ts) return
this.setCurrentParagraph()
}
setCurrentParagraph() {
const { play_ts } = this.props.audio
- const insideParagraph = this.state.paragraphs.some(paragraph => {
+ const insideParagraph = this.props.paragraphs.some(paragraph => {
if (floatLTE(paragraph.start_ts, play_ts) && floatLT(play_ts, paragraph.end_ts)) {
this.setCurrentAnnotation(paragraph, play_ts)
return true
@@ -62,66 +53,13 @@ class ParagraphList extends Component {
this.setState({ currentParagraph, currentAnnotation })
}
- build() {
- const { order: annotationOrder, lookup: annotationLookup } = this.props.annotation
- const { lookup: paragraphLookup } = this.props.paragraph
- let currentParagraph = {}
- let sectionCount = 0
- const paragraphs = []
- // loop over the annotations in time order
- annotationOrder.forEach((annotation_id, i) => {
- const annotation = annotationLookup[annotation_id]
- const paragraph = paragraphLookup[annotation.paragraph_id]
- // if this annotation is media, insert it after the current paragraph
- if (MEDIA_TYPES.has(annotation.type)) {
- paragraphs.push({
- id: ('index_' + i),
- type: annotation.type,
- start_ts: annotation.start_ts,
- end_ts: 0,
- annotations: [annotation],
- })
- return
- }
- // if this annotation is from a different paragraph, make a new paragraph
- if (annotation.type === 'header' || annotation.paragraph_id !== currentParagraph.id) {
- const paragraph_type = getParagraphType(annotation, paragraph)
- currentParagraph = {
- id: annotation.paragraph_id || ('index_' + i),
- type: paragraph_type,
- start_ts: annotation.start_ts,
- end_ts: 0,
- annotations: [],
- }
- if (annotation.type === 'header') {
- currentParagraph.sectionIndex = sectionCount++
- currentParagraph.id = 'section_' + currentParagraph.sectionIndex
- }
- paragraphs.push(currentParagraph)
- }
- // if this annotation is a paragraph_end, set the end timestamp
- if (annotation.type === 'paragraph_end') {
- currentParagraph.end_ts = annotation.start_ts
- }
- // otherwise, just append this annotation to the paragraph
- else {
- currentParagraph.annotations.push(annotation)
- }
- })
- for (let i = 0; i < (paragraphs.length - 1); i++) {
- if (!paragraphs[i].end_ts) {
- paragraphs[i].end_ts = paragraphs[i+1].start_ts - 0.1
- }
- }
- this.setState({ paragraphs })
- }
-
render() {
const {
- media, paragraphElementLookup, selectedParagraph,
- onAnnotationClick, onParagraphDoubleClick
+ paragraphs, media,
+ paragraphElementLookup, selectedParagraph,
+ onAnnotationClick, onParagraphDoubleClick,
} = this.props
- const { paragraphs, currentParagraph, currentAnnotation } = this.state
+ const { currentParagraph, currentAnnotation } = this.state
return paragraphs.map(paragraph => {
if (selectedParagraph && selectedParagraph.id === paragraph.id) {
paragraph = selectedParagraph
@@ -146,19 +84,7 @@ class ParagraphList extends Component {
}
}
-const getParagraphType = (annotation, paragraph) => {
- if (annotation.type === 'header') {
- return annotation.type
- }
- if (!paragraph) {
- return annotation.type
- }
- return paragraph.type
-}
-
const mapStateToProps = state => ({
- paragraph: state.paragraph.index,
- annotation: state.annotation.index,
audio: state.audio,
media: state.media.index,
})