summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/utils/transcript.utils.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2020-07-27 19:42:05 +0200
committerJules Laplace <julescarbon@gmail.com>2020-07-27 19:42:05 +0200
commite22cb8a789c0576738fe0965a8f4242a3d3c76af (patch)
tree226e5ec4298f67125ac9c8953e708c84365b7879 /animism-align/frontend/app/utils/transcript.utils.js
parenta43615e0c0d4edc34a0f4a14172e559f00be298a (diff)
process list of paragraphs. fullscreen vs inline
Diffstat (limited to 'animism-align/frontend/app/utils/transcript.utils.js')
-rw-r--r--animism-align/frontend/app/utils/transcript.utils.js81
1 files changed, 81 insertions, 0 deletions
diff --git a/animism-align/frontend/app/utils/transcript.utils.js b/animism-align/frontend/app/utils/transcript.utils.js
new file mode 100644
index 0000000..8386227
--- /dev/null
+++ b/animism-align/frontend/app/utils/transcript.utils.js
@@ -0,0 +1,81 @@
+import { store, history, dispatch } from 'app/store'
+import {
+ TEXT_ANNOTATION_TYPES,
+ MEDIA_ANNOTATION_TYPES,
+ UTILITY_ANNOTATION_TYPES,
+} from 'app/constants'
+
+export const buildParagraphs = annotationOrder => {
+ const state = store.getState()
+ const { lookup: annotationLookup } = state.annotation.index
+ const { lookup: paragraphLookup } = state.paragraph.index
+ 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 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
+ if (!annotation.settings.hideCitation) {
+ 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 === 'section_heading' || annotation.type === 'heading_text' || 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 === 'section_heading') {
+ 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
+ }
+ }
+ return paragraphs
+}
+
+const getParagraphType = (annotation, paragraph) => {
+ if (annotation.type === 'section_heading') {
+ return annotation.type
+ }
+ if (annotation.type === 'heading_text') {
+ return annotation.type
+ }
+ if (!paragraph) {
+ return annotation.type
+ }
+ return paragraph.type
+}