2018-01-11 01:30:17 +01:00
|
|
|
import React from 'react';
|
|
|
|
import {connect} from 'react-redux';
|
|
|
|
|
|
|
|
class Preview extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
previewSource: '',
|
|
|
|
}
|
|
|
|
this.previewFile = this.previewFile.bind(this);
|
|
|
|
}
|
|
|
|
componentWillMount () {
|
|
|
|
console.log('Preview will mount');
|
|
|
|
if (this.props.file) {
|
|
|
|
this.previewFile(this.props.file);
|
|
|
|
}
|
|
|
|
}
|
2018-01-11 02:41:17 +01:00
|
|
|
componentWillReceiveProps (newProps) {
|
|
|
|
console.log('Preview will receive props', newProps);
|
|
|
|
this.previewFile(newProps.file);
|
2018-01-11 01:30:17 +01:00
|
|
|
}
|
|
|
|
previewFile (file) {
|
|
|
|
console.log('previewFile', file)
|
|
|
|
const that = this;
|
|
|
|
if (file.type !== 'video/mp4') {
|
|
|
|
const previewReader = new FileReader();
|
|
|
|
previewReader.readAsDataURL(file);
|
|
|
|
previewReader.onloadend = function () {
|
|
|
|
that.setState({previewSource: previewReader.result});
|
|
|
|
};
|
|
|
|
} else {
|
2018-01-11 02:41:17 +01:00
|
|
|
that.setState({previewSource: (this.props.thumbnail || '/assets/img/video_thumb_default.png')});
|
2018-01-11 01:30:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<img
|
|
|
|
id="asset-preview"
|
|
|
|
src={this.state.previewSource}
|
|
|
|
className={this.props.dimPreview ? 'dim' : ''}
|
|
|
|
alt="publish preview"
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
|
|
|
return {
|
2018-01-11 02:41:17 +01:00
|
|
|
file : state.file,
|
|
|
|
thumbnail: state.metadata.thumbnail,
|
2018-01-11 01:30:17 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, null)(Preview);
|