This commit is contained in:
cyril lopez 2018-07-06 14:15:59 +02:00
parent b48dced09d
commit d319d22f91
2 changed files with 9 additions and 4 deletions

View File

@ -8,7 +8,7 @@
/* eslint-disable no-console */ /* eslint-disable no-console */
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { get, has, isArray, isEmpty, size } from 'lodash'; import { get, has, isArray, isEmpty, startsWith, size } from 'lodash';
import cn from 'classnames'; import cn from 'classnames';
import BkgImg from 'assets/icons/icon_upload.svg'; import BkgImg from 'assets/icons/icon_upload.svg';
@ -31,9 +31,10 @@ class ImgPreview extends React.Component {
componentDidMount() { componentDidMount() {
// We don't need the generateImgURL function here since the compo will // We don't need the generateImgURL function here since the compo will
// always have an init value here // always have an init value here
const file = this.props.multiple ? get(this.props.files, ['0', 'name'], '') : get(this.props.files, 'name');
this.setState({ this.setState({
imgURL: get(this.props.files, ['0', 'url'], '') || get(this.props.files, 'url', ''), imgURL: get(this.props.files, ['0', 'url'], '') || get(this.props.files, 'url', ''),
isImg: this.isPictureType(get(this.props.files, ['0', 'name'], '')), isImg: this.isPictureType(file),
}); });
} }
@ -142,10 +143,12 @@ class ImgPreview extends React.Component {
renderContent = () => { renderContent = () => {
const fileType = this.getFileType(this.state.imgURL); const fileType = this.getFileType(this.state.imgURL);
if (this.state.isImg) { if (this.state.isImg) {
const imgURL = startsWith(this.state.imgURL, '/') ? `${strapi.backendURL}${this.state.imgURL}` : this.state.imgURL;
return ( return (
<img src={this.state.imgURL} alt="" /> <img src={imgURL} alt="" />
); );
} }
@ -159,6 +162,7 @@ class ImgPreview extends React.Component {
render() { render() {
const { files, onBrowseClick } = this.props; const { files, onBrowseClick } = this.props;
const { imgURL } = this.state; const { imgURL } = this.state;
const containerStyle = isEmpty(imgURL) ? const containerStyle = isEmpty(imgURL) ?
{ {
backgroundImage: `url(${BkgImg})`, backgroundImage: `url(${BkgImg})`,

View File

@ -14,6 +14,7 @@ import GlobalPagination from 'components/GlobalPagination';
import styles from './styles.scss'; import styles from './styles.scss';
/* eslint-disable jsx-a11y/label-has-for */
function PageFooter(props) { function PageFooter(props) {
return ( return (
<div className={cn('row', styles.pageFooter)} style={props.style}> <div className={cn('row', styles.pageFooter)} style={props.style}>