summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/editor/captions/components/galleryCaption.form.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2021-03-12 19:34:30 +0100
committerJules Laplace <julescarbon@gmail.com>2021-03-12 19:34:30 +0100
commitcd84d1fbf26a9272b56fec30fa6e1c30bebe7e06 (patch)
tree0eff1a2153ab5402b1e45e78f685cf93d78f27b5 /animism-align/frontend/app/views/editor/captions/components/galleryCaption.form.js
parentcb47d6a07b857ffc11e5baec07ec9d49439f14e4 (diff)
nicer automatic captions
Diffstat (limited to 'animism-align/frontend/app/views/editor/captions/components/galleryCaption.form.js')
-rw-r--r--animism-align/frontend/app/views/editor/captions/components/galleryCaption.form.js115
1 files changed, 115 insertions, 0 deletions
diff --git a/animism-align/frontend/app/views/editor/captions/components/galleryCaption.form.js b/animism-align/frontend/app/views/editor/captions/components/galleryCaption.form.js
new file mode 100644
index 0000000..ff07052
--- /dev/null
+++ b/animism-align/frontend/app/views/editor/captions/components/galleryCaption.form.js
@@ -0,0 +1,115 @@
+import React, { Component } from 'react'
+import { Link } from 'react-router-dom'
+
+import { TextArea, Button } from 'app/common'
+import actions from 'app/actions'
+
+export default class GalleryCaptionForm extends Component {
+ state = {
+ editing: false,
+ item: {},
+ }
+
+ constructor(props) {
+ super(props)
+ this.edit = this.edit.bind(this)
+ this.handleChange = this.handleChange.bind(this)
+ this.handleSubmit = this.handleSubmit.bind(this)
+ this.handleCancel = this.handleCancel.bind(this)
+ }
+
+ componentDidMount() {
+ this.setState({
+ item: {
+ ...this.props.item,
+ }
+ })
+ }
+
+ edit() {
+ this.setState({ editing: true })
+ }
+
+ handleChange(e){
+ e.preventDefault()
+ this.setState({
+ item: {
+ ...this.state.item,
+ caption: e.target.value,
+ }
+ })
+ }
+
+ handleSubmit(e) {
+ e.preventDefault()
+ this.props.onUpdate(this.props.caption_id, this.state.item)
+ this.setState({ editing: false })
+ }
+
+ handleCancel(e) {
+ e.preventDefault()
+ this.setState({
+ editing: false,
+ item: { ...this.props.item }
+ })
+ }
+
+ render() {
+ return this.state.editing
+ ? this.renderForm()
+ : this.renderEntry()
+ }
+
+ renderForm() {
+ const { episode, index } = this.props
+ const { item } = this.state
+ return (
+ <form className='caption-form' onSubmit={this.handleSubmit}>
+ <TextArea
+ title={`Edit caption`}
+ name="caption"
+ placeholder="Enter caption"
+ data={item}
+ onChange={this.handleChange}
+ />
+ <div className='buttons'>
+ <span />
+ <div>
+ <button onClick={this.handleSubmit}>Save caption</button>
+ <button onClick={this.handleCancel}>Cancel</button>
+ </div>
+ </div>
+ </form>
+ )
+ }
+
+ renderEntry() {
+ const { index } = this.props
+ const { item } = this.state
+ return (
+ <div>
+ <div className={item.caption ? 'caption-entry' : 'caption-entry generated'} onClick={this.edit}>
+ <div className='caption-index'>
+ {index}{'. '}
+ </div>
+ {item.caption
+ ? <div className='caption-text' dangerouslySetInnerHTML={{ __html: item.caption }} />
+ : this.renderAutomaticCaption()
+ }
+ </div>
+ </div>
+ )
+ }
+
+ renderAutomaticCaption() {
+ const { item } = this.state
+ return (
+ <div className='caption-text'>
+ {item.author ? item.author + '. ' : ''}
+ {item.title ? item.title + '. ' : ''}
+ {item.date}
+ {' (Generated)'}
+ </div>
+ )
+ }
+}