From cd84d1fbf26a9272b56fec30fa6e1c30bebe7e06 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 12 Mar 2021 19:34:30 +0100 Subject: nicer automatic captions --- .../editor/captions/components/caption.form.js | 189 +++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 animism-align/frontend/app/views/editor/captions/components/caption.form.js (limited to 'animism-align/frontend/app/views/editor/captions/components/caption.form.js') diff --git a/animism-align/frontend/app/views/editor/captions/components/caption.form.js b/animism-align/frontend/app/views/editor/captions/components/caption.form.js new file mode 100644 index 0000000..3e38ea8 --- /dev/null +++ b/animism-align/frontend/app/views/editor/captions/components/caption.form.js @@ -0,0 +1,189 @@ +import React, { Component } from 'react' +import { Link } from 'react-router-dom' + +import { TextArea, Button } from 'app/common' +import GalleryCaptionForm from './galleryCaption.form' +import actions from 'app/actions' + +const ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split("") + +export default class CaptionForm extends Component { + state = { + editing: false, + expanded: false, + media: { settings: {} }, + } + + constructor(props) { + super(props) + this.edit = this.edit.bind(this) + this.expand = this.expand.bind(this) + this.handleChange = this.handleChange.bind(this) + this.handleSubmit = this.handleSubmit.bind(this) + this.handleCancel = this.handleCancel.bind(this) + this.handleUpdateGalleryCaption = this.handleUpdateGalleryCaption.bind(this) + } + + componentDidMount() { + this.setState({ + media: { + ...this.props.media, + settings: { + ...this.props.media.settings, + } + } + }) + } + + edit() { + this.setState({ editing: true }) + } + expand() { + this.setState({ expanded: !this.state.expanded }) + } + + handleChange(e){ + e.preventDefault() + this.setState({ + media: { + ...this.state.media, + settings: { + ...this.state.media, + bibliography: e.target.value, + } + } + }) + } + + handleSubmit(e) { + e.preventDefault() + actions.media.update(this.state.media) + this.setState({ editing: false }) + } + + handleUpdateGalleryCaption(caption_id, item) { + const media = { + ...this.state.media, + settings: { + ...this.state.media.settings, + caption_lookup: { + ...this.state.media.settings.caption_lookup, + [caption_id]: { ...item } + } + } + } + // console.log(media) + actions.media.update(media) + this.setState({ media }) + } + + handleCancel(e) { + e.preventDefault() + this.setState({ + editing: false, + media: { ...this.props.media } + }) + } + + render() { + return this.state.editing + ? this.renderForm() + : this.renderEntry() + } + + renderForm() { + const { episode, index } = this.props + const { media } = this.state + return ( +
+