diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-07-23 22:19:12 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-07-23 22:19:12 +0200 |
| commit | bcb7c778eee1a2dd14fe222f7a30eada1fd8f902 (patch) | |
| tree | d95a9b19ddc4a8a4bd925e909937433c6b714f0e /animism-align/frontend/app/views/viewer/viewer.actions.js | |
| parent | 28bdef87320412776ff0db071f8ab89a51834cac (diff) | |
pulling out section list
Diffstat (limited to 'animism-align/frontend/app/views/viewer/viewer.actions.js')
| -rw-r--r-- | animism-align/frontend/app/views/viewer/viewer.actions.js | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/animism-align/frontend/app/views/viewer/viewer.actions.js b/animism-align/frontend/app/views/viewer/viewer.actions.js index 7f8e1c8..35e26a9 100644 --- a/animism-align/frontend/app/views/viewer/viewer.actions.js +++ b/animism-align/frontend/app/views/viewer/viewer.actions.js @@ -1,14 +1,51 @@ import * as types from 'app/types' import { store, history, dispatch } from 'app/store' -// import { } from 'app/utils' -// import actions from 'app/actions' +import { MEDIA_TYPES } from 'app/constants' + +const newSection = (annotation, index) => ({ + start_ts: annotation.start_ts, + title: annotation.text, + media: [], + index, +}) + +export const loadSections = () => dispatch => { + let sections = [], currentSection + const state = store.getState() + const { order: annotationOrder, lookup: annotationLookup } = state.annotation.index + const { lookup: mediaLookup } = state.media.index + console.log(state.media.index) + + // loop over the annotations in time order. group the media found in each section. + annotationOrder.forEach((annotation_id, i) => { + const annotation = annotationLookup[annotation_id] + if (annotation.type === 'header') { + currentSection = newSection(annotation, sections.length) + sections.push(currentSection) + } + if (MEDIA_TYPES.has(annotation.type)) { + if (!currentSection) { + console.error("media found before first section") + return + } + const media = mediaLookup[annotation.settings.media_id] + currentSection.media.push(media) + } + }) + + console.log(sections) + + dispatch({ type: types.viewer.load_sections, data: sections }) +} export const showSection = section => dispatch => { dispatch({ type: types.viewer.toggle_section, key: section, value: true }) } + export const hideSection = section => dispatch => { dispatch({ type: types.viewer.toggle_section, key: section, value: false }) } + export const toggleSection = section => dispatch => { dispatch({ type: types.viewer.toggle_section, key: section, value: !store.getState().viewer[section] }) } |
