summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/paragraph/transcript.actions.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2020-07-27 15:44:29 +0200
committerJules Laplace <julescarbon@gmail.com>2020-07-27 15:44:29 +0200
commit2aad507650fa3263ef81be759ab0531b43e5b7cc (patch)
treeb8299f962ef0e3342cb8978f5e0a4f57a8ee1b30 /animism-align/frontend/app/views/paragraph/transcript.actions.js
parenteee3193ecf604eaed30505128b2a1f7bb875d44a (diff)
annotation form for curtain events. refactor utilities
Diffstat (limited to 'animism-align/frontend/app/views/paragraph/transcript.actions.js')
-rw-r--r--animism-align/frontend/app/views/paragraph/transcript.actions.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/animism-align/frontend/app/views/paragraph/transcript.actions.js b/animism-align/frontend/app/views/paragraph/transcript.actions.js
new file mode 100644
index 0000000..3d2b045
--- /dev/null
+++ b/animism-align/frontend/app/views/paragraph/transcript.actions.js
@@ -0,0 +1,69 @@
+import * as types from 'app/types'
+import { store, history, dispatch } from 'app/store'
+import { MEDIA_TYPES } from 'app/constants'
+
+export const buildParagraphs = () => dispatch => {
+ const state = store.getState()
+ const { order: annotationOrder, 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 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
+ }
+ }
+ dispatch({ type: types.paragraph.update_transcript, paragraphs })
+}
+
+const getParagraphType = (annotation, paragraph) => {
+ if (annotation.type === 'header') {
+ return annotation.type
+ }
+ if (!paragraph) {
+ return annotation.type
+ }
+ return paragraph.type
+}
+