summaryrefslogtreecommitdiff
path: root/animism-align
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2020-07-27 23:09:08 +0200
committerJules Laplace <julescarbon@gmail.com>2020-07-27 23:09:08 +0200
commit443f0a465c720c9e70a124671872c74bc7e9bbd4 (patch)
tree6487601fe40c2b388d74792daf8934444fef1517 /animism-align
parentb54da8c0e7e062cee8406d642e4cc7170d279753 (diff)
update section index corretly
Diffstat (limited to 'animism-align')
-rw-r--r--animism-align/frontend/app/utils/transcript.utils.js13
-rw-r--r--animism-align/frontend/app/views/viewer/viewer.actions.js4
2 files changed, 13 insertions, 4 deletions
diff --git a/animism-align/frontend/app/utils/transcript.utils.js b/animism-align/frontend/app/utils/transcript.utils.js
index c913f9a..5a56611 100644
--- a/animism-align/frontend/app/utils/transcript.utils.js
+++ b/animism-align/frontend/app/utils/transcript.utils.js
@@ -5,21 +5,26 @@ import {
UTILITY_ANNOTATION_TYPES,
} from 'app/constants'
-export const buildParagraphs = annotationOrder => {
+export const buildParagraphs = (annotationOrder, sectionCount) => {
const state = store.getState()
const { lookup: annotationLookup } = state.annotation.index
const { lookup: paragraphLookup } = state.paragraph.index
let currentParagraph = {}
- let sectionCount = 0
const paragraphs = []
+
+ sectionCount = (sectionCount || 0)
+
// loop over the annotations in time order
annotationOrder.forEach((annotation_id, i) => {
+ // fetch annotation and paragraph
const annotation = annotationLookup[annotation_id]
const paragraph = paragraphLookup[annotation.paragraph_id]
+
// if this annotation is a utility (curtain, gallery instructions), then skip it
if (UTILITY_ANNOTATION_TYPES.has(annotation.type)) {
return
}
+
// if this annotation is media, then insert it after the current paragraph
if (MEDIA_ANNOTATION_TYPES.has(annotation.type)) {
// add option to hide the citation from the transcript
@@ -34,6 +39,7 @@ export const buildParagraphs = annotationOrder => {
}
return
}
+
// if this annotation is from a different paragraph, make a new paragraph
if (annotation.type === 'section_heading' || annotation.type === 'heading_text' || annotation.paragraph_id !== currentParagraph.id) {
const paragraph_type = getParagraphType(annotation, paragraph)
@@ -50,15 +56,18 @@ export const buildParagraphs = annotationOrder => {
}
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)
}
})
+
// finally, go over the paragraphs and update their end_ts, if none is set
for (let i = 0; i < (paragraphs.length - 1); i++) {
if (!paragraphs[i].end_ts) {
diff --git a/animism-align/frontend/app/views/viewer/viewer.actions.js b/animism-align/frontend/app/views/viewer/viewer.actions.js
index 40a4718..836c677 100644
--- a/animism-align/frontend/app/views/viewer/viewer.actions.js
+++ b/animism-align/frontend/app/views/viewer/viewer.actions.js
@@ -54,7 +54,7 @@ export const loadSections = () => dispatch => {
// finish off the previous section.
if (currentSection) {
currentSection.mediaLabels = Object.keys(currentMediaLabels).join(', ')
- currentSection.paragraphs = buildParagraphs(sectionTextAnnotationOrder)
+ currentSection.paragraphs = buildParagraphs(sectionTextAnnotationOrder, currentSection.index)
currentSection.end_ts = currentSection.paragraphs[currentSection.paragraphs.length - 1].end_ts
}
// create a new section and reset state variables
@@ -109,7 +109,7 @@ export const loadSections = () => dispatch => {
// finished processing all annotations. finish off the last section.
if (currentSection) {
currentSection.mediaLabels = Object.keys(currentMediaLabels).join(', ')
- currentSection.paragraphs = buildParagraphs(sectionTextAnnotationOrder)
+ currentSection.paragraphs = buildParagraphs(sectionTextAnnotationOrder, currentSection.index)
currentSection.end_ts = timeline.duration
}