From 7e6dfb31af78b9d5a1a4ccec6998b14beb8a1194 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 10 Mar 2021 17:33:21 +0100 Subject: refactor annotation forms out of the directory nest --- .../app/views/dashboard/dashboard.container.js | 2 +- .../app/views/editor/align/align.container.js | 6 +- .../components/annotations/annotation.form.css | 67 -------- .../components/annotations/annotation.form.js | 186 --------------------- .../components/annotations/annotation.index.css | 125 -------------- .../components/annotations/annotation.index.js | 126 -------------- .../annotationForms/annotationForm.gallery.js | 132 --------------- .../annotationForms/annotationForm.image.js | 120 ------------- .../annotationForms/annotationForm.text.js | 153 ----------------- .../annotationForms/annotationForm.utility.js | 172 ------------------- .../annotationForms/annotationForm.video.js | 160 ------------------ .../annotations/annotationForms/index.js | 46 ----- .../annotationTypes/annotationTypes.gallery.js | 75 --------- .../annotationTypes/annotationTypes.image.js | 54 ------ .../annotationTypes/annotationTypes.text.js | 121 -------------- .../annotationTypes/annotationTypes.utility.js | 107 ------------ .../annotationTypes/annotationTypes.video.js | 51 ------ .../annotations/annotationTypes/index.js | 57 ------- .../align/containers/annotations.container.js | 28 ---- .../editor/align/containers/timeline.container.js | 12 +- .../views/editor/annotation/annotation.form.css | 67 ++++++++ .../views/editor/annotation/annotation.index.css | 125 ++++++++++++++ .../editor/annotation/annotations.container.js | 31 ++++ .../annotation/components/annotation.form.js | 186 +++++++++++++++++++++ .../annotation/components/annotation.index.js | 126 ++++++++++++++ .../annotationForms/annotationForm.gallery.js | 132 +++++++++++++++ .../annotationForms/annotationForm.image.js | 120 +++++++++++++ .../annotationForms/annotationForm.text.js | 153 +++++++++++++++++ .../annotationForms/annotationForm.utility.js | 172 +++++++++++++++++++ .../annotationForms/annotationForm.video.js | 160 ++++++++++++++++++ .../annotation/components/annotationForms/index.js | 46 +++++ .../annotationTypes/annotationTypes.gallery.js | 75 +++++++++ .../annotationTypes/annotationTypes.image.js | 54 ++++++ .../annotationTypes/annotationTypes.text.js | 121 ++++++++++++++ .../annotationTypes/annotationTypes.utility.js | 107 ++++++++++++ .../annotationTypes/annotationTypes.video.js | 51 ++++++ .../annotation/components/annotationTypes/index.js | 57 +++++++ .../views/editor/overview/overview.container.js | 10 +- 38 files changed, 1798 insertions(+), 1795 deletions(-) delete mode 100644 animism-align/frontend/app/views/editor/align/components/annotations/annotation.form.css delete mode 100644 animism-align/frontend/app/views/editor/align/components/annotations/annotation.form.js delete mode 100644 animism-align/frontend/app/views/editor/align/components/annotations/annotation.index.css delete mode 100644 animism-align/frontend/app/views/editor/align/components/annotations/annotation.index.js delete mode 100644 animism-align/frontend/app/views/editor/align/components/annotations/annotationForms/annotationForm.gallery.js delete mode 100644 animism-align/frontend/app/views/editor/align/components/annotations/annotationForms/annotationForm.image.js delete mode 100644 animism-align/frontend/app/views/editor/align/components/annotations/annotationForms/annotationForm.text.js delete mode 100644 animism-align/frontend/app/views/editor/align/components/annotations/annotationForms/annotationForm.utility.js delete mode 100644 animism-align/frontend/app/views/editor/align/components/annotations/annotationForms/annotationForm.video.js delete mode 100644 animism-align/frontend/app/views/editor/align/components/annotations/annotationForms/index.js delete mode 100644 animism-align/frontend/app/views/editor/align/components/annotations/annotationTypes/annotationTypes.gallery.js delete mode 100644 animism-align/frontend/app/views/editor/align/components/annotations/annotationTypes/annotationTypes.image.js delete mode 100644 animism-align/frontend/app/views/editor/align/components/annotations/annotationTypes/annotationTypes.text.js delete mode 100644 animism-align/frontend/app/views/editor/align/components/annotations/annotationTypes/annotationTypes.utility.js delete mode 100644 animism-align/frontend/app/views/editor/align/components/annotations/annotationTypes/annotationTypes.video.js delete mode 100644 animism-align/frontend/app/views/editor/align/components/annotations/annotationTypes/index.js delete mode 100644 animism-align/frontend/app/views/editor/align/containers/annotations.container.js create mode 100644 animism-align/frontend/app/views/editor/annotation/annotation.form.css create mode 100644 animism-align/frontend/app/views/editor/annotation/annotation.index.css create mode 100644 animism-align/frontend/app/views/editor/annotation/annotations.container.js create mode 100644 animism-align/frontend/app/views/editor/annotation/components/annotation.form.js create mode 100644 animism-align/frontend/app/views/editor/annotation/components/annotation.index.js create mode 100644 animism-align/frontend/app/views/editor/annotation/components/annotationForms/annotationForm.gallery.js create mode 100644 animism-align/frontend/app/views/editor/annotation/components/annotationForms/annotationForm.image.js create mode 100644 animism-align/frontend/app/views/editor/annotation/components/annotationForms/annotationForm.text.js create mode 100644 animism-align/frontend/app/views/editor/annotation/components/annotationForms/annotationForm.utility.js create mode 100644 animism-align/frontend/app/views/editor/annotation/components/annotationForms/annotationForm.video.js create mode 100644 animism-align/frontend/app/views/editor/annotation/components/annotationForms/index.js create mode 100644 animism-align/frontend/app/views/editor/annotation/components/annotationTypes/annotationTypes.gallery.js create mode 100644 animism-align/frontend/app/views/editor/annotation/components/annotationTypes/annotationTypes.image.js create mode 100644 animism-align/frontend/app/views/editor/annotation/components/annotationTypes/annotationTypes.text.js create mode 100644 animism-align/frontend/app/views/editor/annotation/components/annotationTypes/annotationTypes.utility.js create mode 100644 animism-align/frontend/app/views/editor/annotation/components/annotationTypes/annotationTypes.video.js create mode 100644 animism-align/frontend/app/views/editor/annotation/components/annotationTypes/index.js (limited to 'animism-align') diff --git a/animism-align/frontend/app/views/dashboard/dashboard.container.js b/animism-align/frontend/app/views/dashboard/dashboard.container.js index fa06329..0d4da43 100644 --- a/animism-align/frontend/app/views/dashboard/dashboard.container.js +++ b/animism-align/frontend/app/views/dashboard/dashboard.container.js @@ -65,7 +65,7 @@ class DashboardContainer extends Component { {projects.order.map((project_id) => { const project = projects.lookup[project_id] - console.log(project) + // console.log(project) return (
diff --git a/animism-align/frontend/app/views/editor/align/align.container.js b/animism-align/frontend/app/views/editor/align/align.container.js index 281fd35..168551d 100644 --- a/animism-align/frontend/app/views/editor/align/align.container.js +++ b/animism-align/frontend/app/views/editor/align/align.container.js @@ -1,11 +1,9 @@ import React, { Component } from 'react' import './align.css' -import './components/annotations/annotation.form.css' -import './components/annotations/annotation.index.css' -import Timeline from 'app/views/editor/align/containers/timeline.container.js' -import Sidebar from 'app/views/editor/align/containers/sidebar.container.js' +import Timeline from './containers/timeline.container.js' +import Sidebar from './containers/sidebar.container.js' class Container extends Component { componentDidMount() { diff --git a/animism-align/frontend/app/views/editor/align/components/annotations/annotation.form.css b/animism-align/frontend/app/views/editor/align/components/annotations/annotation.form.css deleted file mode 100644 index fa663c7..0000000 --- a/animism-align/frontend/app/views/editor/align/components/annotations/annotation.form.css +++ /dev/null @@ -1,67 +0,0 @@ -/* Annotation form */ - -.annotationForm { - width: 401px; - padding: 0.5rem; - position: absolute; - left: 0.25rem; - background: #448; - box-shadow: 0 0 2px #000, 0 0 4px #000; - z-index: 10; -} -.annotationForm textarea { - width: 100%; -} -.annotationForm .row { - justify-content: space-between; - align-items: center; -} -.annotationForm .row > div { - display: flex; - align-items: center; -} -.annotationForm .buttons { - margin-bottom: 0.5rem; -} -.annotationForm .ts { - color: #fff; -} -.annotationForm .select.media_id { - width: 100%; - margin-right: 0; -} -.annotationForm div.textarea { - margin-bottom: 0.5rem; -} -.annotationForm img { - max-width: 100%; - max-height: 6rem; -} - -.annotationForm .options label span:first-child { - display: inline-block; - width: 6rem; -} -.annotationForm .options .description { - font-size: 0.75rem; - margin-top: 0.25rem; - margin-bottom: 0.5rem; -} -.annotationForm .color input[type="text"].number { - width: 8rem; -} -.annotationForm .color input[type="text"] { - width: 8rem; -} -.annotationForm .color input[type="color"] { - background: transparent; - border: 0; - height: 1.7rem; - padding: 0; - margin: 0 0.5rem 0 0; - width: 1.4rem; -} -.annotationForm .checkbox { - margin-top: 0.5rem; - margin-bottom: 0.5rem; -} \ No newline at end of file diff --git a/animism-align/frontend/app/views/editor/align/components/annotations/annotation.form.js b/animism-align/frontend/app/views/editor/align/components/annotations/annotation.form.js deleted file mode 100644 index 6804cdd..0000000 --- a/animism-align/frontend/app/views/editor/align/components/annotations/annotation.form.js +++ /dev/null @@ -1,186 +0,0 @@ -import React, { Component } from 'react' -// import { Link } from 'react-router-dom' -import { connect } from 'react-redux' - -import actions from 'app/actions' - -import { ANNOTATION_SELECT_OPTIONS, MEDIA_ANNOTATION_TYPES } from 'app/constants' -import { timestamp } from 'app/utils' -import { timeToPosition } from 'app/utils/align.utils' -import { Select } from 'app/common' - -import { annotationFormLookup } from './annotationForms' - -const annotationTextTypes = new Set([ - 'sentence', 'section_heading', 'heading_text', 'pullquote_credit', 'footnote', 'text_plate', -]) - -class AnnotationForm extends Component { - constructor(props){ - super(props) - this.handleChange = this.handleChange.bind(this) - this.handleSelect = this.handleSelect.bind(this) - this.handleSettingsChange = this.handleSettingsChange.bind(this) - this.handleSettingsSelect = this.handleSettingsSelect.bind(this) - this.handleKeyDown = this.handleKeyDown.bind(this) - this.handleSubmit = this.handleSubmit.bind(this) - this.handleDestroy = this.handleDestroy.bind(this) - this.textareaRef = React.createRef() - } - componentDidMount() { - if (this.textareaRef && this.textareaRef.current) { - this.textareaRef.current.focus() - } - } - handleKeyDown(e) { - if (e.keyCode === 27) { // escape - actions.align.hideAnnotationForm() - return - } - // console.log(e.keyCode) - if (!e.metaKey && !e.ctrlKey) return - let { start_ts } = this.props.annotation - switch (e.keyCode) { - case 38: // up - e.preventDefault() - start_ts -= 0.1 - actions.align.updateAnnotationForm('start_ts', Math.max(0, start_ts)) - actions.audio.seek(start_ts) - actions.align.setCursor(start_ts) - break - case 40: // down - e.preventDefault() - start_ts += 0.1 - actions.align.updateAnnotationForm('start_ts', Math.max(0, start_ts)) - actions.audio.seek(start_ts) - actions.align.setCursor(start_ts) - break - case 83: // ctrl-S - e.preventDefault() - this.handleSubmit() - default: - break - } - } - handleChange(e) { - const { name, value } = e.target - this.handleSelect(name, value) - } - handleSelect(name, value) { - actions.align.updateAnnotationForm(name, value) - } - handleSettingsChange(e) { - const { name, value } = e.target - this.handleSettingsSelect(name, value) - } - handleSettingsSelect(name, value) { - if (name.indexOf('_id') !== -1) value = parseInt(value) || 0 - actions.align.updateAnnotationSettings(name, value) - } - handleSubmit() { - const { annotation } = this.props - if (annotation.type === 'paragraph_end') { - annotation.text = '' - } - if (annotation.type in MEDIA_ANNOTATION_TYPES) { - if (!annotation.settings.media_id) return - annotation.text = '' - } - if (annotation.id === 'new') { - delete annotation.id - actions.annotation.create(annotation) - .then(response => { - console.log(response) - actions.align.hideAnnotationForm() - }) - } else { - actions.annotation.update(annotation) - .then(response => { - console.log(response) - actions.align.hideAnnotationForm() - }) - } - } - handleDestroy() { - const { annotation } = this.props - if (annotation.id === 'new') { - actions.align.hideAnnotationForm() - } else { - actions.annotation.destroy(annotation) - .then(response => { - console.log(response) - actions.align.hideAnnotationForm() - }) - } - } - render() { - const { timeline, annotation } = this.props - return ( -
- {this.renderButtons()} - {annotationTextTypes.has(annotation.type) && this.renderTextarea()} - {(annotation.type in annotationFormLookup) && this.renderElementForm()} -
- ) - } - renderButtons() { - const { annotation } = this.props - return ( -
-
-