From 73b0e74bd668f2aad6a319a6042aed5f0a8bc80d Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 10 Aug 2020 18:10:29 +0200 Subject: starting form gallery --- .../app/views/media/components/media.form.js | 13 +- .../views/media/components/media.formGallery.js | 146 +++++++++++++++++++++ .../frontend/app/views/viewer/viewer.actions.js | 2 +- 3 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 animism-align/frontend/app/views/media/components/media.formGallery.js diff --git a/animism-align/frontend/app/views/media/components/media.form.js b/animism-align/frontend/app/views/media/components/media.form.js index 76d6f3e..60b8736 100644 --- a/animism-align/frontend/app/views/media/components/media.form.js +++ b/animism-align/frontend/app/views/media/components/media.form.js @@ -8,9 +8,10 @@ import { TextInput, LabelDescription, Select, TextArea, Checkbox, SubmitButton, import MediaImageForm from './media.formImage' import MediaVideoForm from './media.formVideo' import MediaFileForm from './media.formFile' +import MediaGalleryForm from './media.formGallery' const newMedia = () => ({ - type: 'image', + type: 'gallery', tag: 'media', url: '', title: '', @@ -26,7 +27,7 @@ const newMedia = () => ({ }) const MEDIA_UPLOAD_TYPES = [ - 'image', 'video', 'file', + 'image', 'video', 'file', 'gallery', ].map(name => ({ name, label: capitalize(name) })) export default class MediaForm extends Component { @@ -181,6 +182,14 @@ export default class MediaForm extends Component { /> } + {data.type === 'gallery' && + + } + this.setState({ img })) + } + } + + handleChange(e) { + const { name, value } = e.target + this.handleSelect(name, value) + } + + handleSelect(name, value) { + this.props.onSelect(name, value) + } + + handleSettingsChange(name, value) { + this.props.onSettingsChange(name, value) + } + + handleUpload({ file, img, canvas, blob }) { + // sizes: fullsize, display, thumbnail + this.replaceTaggedSize(file, 'fullsize') + .then(data => { + this.setState({ img }) + this.props.onSettingsChange('multiple', { + fullsize: data, + crop: {}, + }) + return this.replaceTaggedSize(blob, 'display', file.name) + }).then(data => { + this.props.onSettingsChange('multiple', { + display: data, + }) + this.uploadThumbnail(img) + }) + } + + uploadThumbnail(img) { + const { fn } = this.props.data.settings.fullsize + const thumbnailCanvas = renderThumbnail(img, { maxSide: THUMBNAIL_SIZE }) + thumbnailCanvas.toBlob(thumbnail => { + this.replaceTaggedSize(thumbnail, 'thumbnail', fn).then(data => { + this.props.onSettingsChange('multiple', { + thumbnail: data, + }) + }) + }, 'image/jpeg', THUMBNAIL_QUALITY) + } + + replaceTaggedSize(image, tag, fn) { + // when we upload an image, if the image already exists in this "position" + // on the record, we should also delete it + if (this.props.data.settings[tag] && this.props.data.settings[tag].id) { + return new Promise((resolve, reject) => { + actions.upload.destroy(this.props.data.settings[tag]) + .then(() => { + console.log('destroy successful') + this.uploadTaggedSize(image, tag, fn).then(data => resolve(data)) + }) + .catch(() => { + console.log('error deleting the image') + this.uploadTaggedSize(image, tag, fn).then(data => resolve(data)) + }) + }) + } + return this.uploadTaggedSize(image, tag, fn) + } + + uploadTaggedSize(image, tag, fn) { + console.log('uploading size', tag) + const uploadData = { + image, + tag, + username: 'animism', + } + if (fn) { + uploadData['__image_filename'] = fn + } + // console.log(uploadData) + return actions.upload.upload(uploadData).then(data => { + // console.log(data) + return data.res + }) + } + + render() { + const { data } = this.props + // console.log(data) + return ( +
+ {!data.url && + + } + {data.settings.fullsize && +
+ {data.settings.fullsize.url} +
+ } +
+ ) + } +} diff --git a/animism-align/frontend/app/views/viewer/viewer.actions.js b/animism-align/frontend/app/views/viewer/viewer.actions.js index 01f4232..1547606 100644 --- a/animism-align/frontend/app/views/viewer/viewer.actions.js +++ b/animism-align/frontend/app/views/viewer/viewer.actions.js @@ -131,7 +131,7 @@ export const loadSections = () => dispatch => { } } - console.log(sections) + // console.log(sections) // console.log(fullscreenTimeline) dispatch({ type: types.viewer.load_sections, sections, fullscreenTimeline }) } -- cgit v1.2.3-70-g09d2