2018-01-11 01:30:17 +01:00
|
|
|
import React from 'react';
|
2018-01-17 18:24:17 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2018-01-11 01:30:17 +01:00
|
|
|
|
|
|
|
class Preview extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2018-01-17 21:54:26 +01:00
|
|
|
imgSource : '',
|
|
|
|
defaultThumbnail: '/assets/img/video_thumb_default.png',
|
|
|
|
};
|
2018-01-11 01:30:17 +01:00
|
|
|
this.previewFile = this.previewFile.bind(this);
|
|
|
|
}
|
2018-01-18 19:13:51 +01:00
|
|
|
componentDidMount () {
|
2018-01-11 20:41:12 +01:00
|
|
|
this.previewFile(this.props.file);
|
2018-01-11 01:30:17 +01:00
|
|
|
}
|
2018-01-11 02:41:17 +01:00
|
|
|
componentWillReceiveProps (newProps) {
|
2018-01-17 21:54:26 +01:00
|
|
|
if (newProps.file !== this.props.file) {
|
|
|
|
this.previewFile(newProps.file);
|
|
|
|
}
|
|
|
|
if (newProps.thumbnail !== this.props.thumbnail) {
|
|
|
|
this.setState({imgSource: (newProps.thumbnail || this.state.defaultThumbnail)});
|
|
|
|
}
|
2018-01-11 01:30:17 +01:00
|
|
|
}
|
|
|
|
previewFile (file) {
|
|
|
|
const that = this;
|
|
|
|
if (file.type !== 'video/mp4') {
|
|
|
|
const previewReader = new FileReader();
|
|
|
|
previewReader.readAsDataURL(file);
|
|
|
|
previewReader.onloadend = function () {
|
2018-01-17 21:54:26 +01:00
|
|
|
that.setState({imgSource: previewReader.result});
|
2018-01-11 01:30:17 +01:00
|
|
|
};
|
|
|
|
} else {
|
2018-01-17 21:54:26 +01:00
|
|
|
that.setState({imgSource: (this.props.thumbnail || this.state.defaultThumbnail)});
|
2018-01-11 01:30:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<img
|
|
|
|
id="asset-preview"
|
2018-01-17 21:54:26 +01:00
|
|
|
src={this.state.imgSource}
|
2018-01-11 01:30:17 +01:00
|
|
|
className={this.props.dimPreview ? 'dim' : ''}
|
|
|
|
alt="publish preview"
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-01-17 18:24:17 +01:00
|
|
|
Preview.propTypes = {
|
|
|
|
dimPreview: PropTypes.bool.isRequired,
|
|
|
|
file : PropTypes.object.isRequired,
|
|
|
|
thumbnail : PropTypes.string,
|
|
|
|
};
|
|
|
|
|
2018-01-11 20:41:12 +01:00
|
|
|
export default Preview;
|