summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/paragraph/components/paragraph.list.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2021-03-08 22:11:55 +0100
committerJules Laplace <julescarbon@gmail.com>2021-03-08 22:11:55 +0100
commitd2cb17038b8537a609be06be2ed7013dbe27117e (patch)
tree028ceac9edddafc03ce80c49d5a05981bec3fcbe /animism-align/frontend/app/views/paragraph/components/paragraph.list.js
parentb5ceb782f40fc1e402d1e58bc1ced2e4038fd787 (diff)
beginning the BIG refactor. moving editor stuff into per-episode hierarchy
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.js103
1 files changed, 0 insertions, 103 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
deleted file mode 100644
index f7c9c58..0000000
--- a/animism-align/frontend/app/views/paragraph/components/paragraph.list.js
+++ /dev/null
@@ -1,103 +0,0 @@
-import React, { Component } from 'react'
-import { Route } from 'react-router-dom'
-import { bindActionCreators } from 'redux'
-import { connect } from 'react-redux'
-
-import { floatLT, floatInRange, capitalize } from 'app/utils'
-import ParagraphForm from '../components/paragraph.form'
-
-class ParagraphList extends Component {
- state = {
- currentParagraph: -1,
- currentAnnotation: -1,
- }
-
- componentDidUpdate(prevProps) {
- if (this.props.audio.play_ts === prevProps.audio.play_ts) return
- if (!this.props.paragraphs) return
- this.setCurrentParagraph()
- }
-
- setCurrentParagraph() {
- const { play_ts } = this.props.audio
- const insideParagraph = this.props.paragraphs.some(paragraph => {
- if (floatInRange(paragraph.start_ts, play_ts, paragraph.end_ts)) {
- this.setCurrentAnnotation(paragraph, play_ts)
- return true
- }
- return false
- })
- if (!insideParagraph) {
- this.setState({
- currentParagraph: -1,
- currentAnnotation: -1,
- })
- }
- }
-
- setCurrentAnnotation(paragraph, play_ts) {
- const { id: currentParagraph, annotations } = paragraph
- const possibleAnnotations = annotations.filter(a => a.type === 'sentence')
- // console.log(possibleAnnotations)
- if (!possibleAnnotations.length) return
- let currentAnnotation
- let annotation
- let i = 0, next_i
- let len = possibleAnnotations.length
- for (let i = 0; i < len - 1; i++) {
- next_i = i + 1
- if (next_i < len && floatLT(play_ts, possibleAnnotations[next_i].start_ts)) {
- currentAnnotation = possibleAnnotations[i].id
- break
- }
- }
- if (!currentAnnotation) {
- currentAnnotation = possibleAnnotations[len-1].id
- }
- this.setState({ currentParagraph, currentAnnotation })
- }
-
- render() {
- const {
- paragraphs, media,
- paragraphElementLookup, selectedParagraph,
- onAnnotationClick, onParagraphDoubleClick,
- currentSection,
- } = this.props
- const { currentParagraph, currentAnnotation } = this.state
- if (!paragraphs) return null
- return paragraphs.map((paragraph, i) => {
- if (selectedParagraph && selectedParagraph.id === paragraph.id) {
- paragraph = selectedParagraph
- }
- if (paragraph.type in paragraphElementLookup) {
- const ParagraphElement = paragraphElementLookup[paragraph.type]
- return (
- <ParagraphElement
- key={paragraph.id + "_" + i}
- paragraph={paragraph}
- media={media}
- currentSection={currentSection}
- currentParagraph={paragraph.id === currentParagraph}
- currentAnnotation={paragraph.id === currentParagraph && currentAnnotation}
- onAnnotationClick={onAnnotationClick}
- onDoubleClick={onParagraphDoubleClick}
- />
- )
- // } else {
- // return <div key={paragraph.id}>{'(' + capitalize(paragraph.type) + ')'}</div>
- }
- })
- }
-}
-
-const mapStateToProps = state => ({
- audio: state.audio,
- media: state.media.index,
- currentSection: state.viewer.currentSection,
-})
-
-const mapDispatchToProps = dispatch => ({
-})
-
-export default connect(mapStateToProps, mapDispatchToProps)(ParagraphList)