/*
This component supports either uploading and storing a single image, or
an array of images.
Note also that an image can be stored as a simple string, or as an array of formats
(each format being itself an object).
*/
import { Components, getSetting, registerSetting, registerComponent } from 'meteor/vulcan:lib';
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import Dropzone from 'react-dropzone';
import 'cross-fetch/polyfill'; // patch for browser which don't have fetch implemented
import { FormattedMessage } from 'meteor/vulcan:i18n';
registerSetting('cloudinary.cloudName', null, 'Cloudinary cloud name (for image uploads)');
/*
Get a URL from an image or an array of images
*/
const getImageUrl = imageOrImageArray => {
// if image is actually an array of formats, use first format
const image = Array.isArray(imageOrImageArray) ? imageOrImageArray[0] : imageOrImageArray;
// if image is an object, return secure_url; else return image itself
const imageUrl = typeof image === 'string' ? image : image.secure_url;
return imageUrl
}
/*
Remove the nth item from an array
*/
const removeNthItem = (array, n) => [..._.first(array, n), ..._.rest(array, n+1)];
/*
Display a single image
*/
class Image extends PureComponent {
constructor() {
super();
this.clearImage = this.clearImage.bind(this);
}
clearImage(e) {
e.preventDefault();
this.props.clearImage(this.props.index);
}
render() {
return (