2020-10-07 17:40:30 -04:00
|
|
|
const bindAll = require('lodash.bindall');
|
|
|
|
const PropTypes = require('prop-types');
|
|
|
|
const React = require('react');
|
|
|
|
|
|
|
|
const Video = require('../video/video.jsx');
|
2020-11-10 14:37:18 -05:00
|
|
|
const Spinner = require('../spinner/spinner.jsx');
|
2020-10-07 17:40:30 -04:00
|
|
|
|
|
|
|
require('./video-preview.scss');
|
|
|
|
|
|
|
|
class VideoPreview extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
bindAll(this, [
|
2020-11-10 14:37:18 -05:00
|
|
|
'handleShowVideo',
|
|
|
|
'handleVideoLoaded'
|
2020-10-07 17:40:30 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
this.state = {
|
2020-11-10 14:37:18 -05:00
|
|
|
videoOpen: false,
|
|
|
|
spinnerVisible: false
|
2020-10-07 17:40:30 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
handleShowVideo () {
|
2020-11-10 14:37:18 -05:00
|
|
|
this.setState({
|
|
|
|
videoOpen: true,
|
|
|
|
spinnerVisible: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleVideoLoaded () {
|
|
|
|
this.setState({spinnerVisible: false});
|
2020-10-07 17:40:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<div className="video-preview">
|
|
|
|
{this.state.videoOpen ?
|
|
|
|
(
|
2020-11-10 14:37:18 -05:00
|
|
|
<div className="spinner-video-container">
|
|
|
|
{this.state.spinnerVisible ? <Spinner className="loading-spinner" /> : null}
|
|
|
|
<Video
|
|
|
|
className="video"
|
|
|
|
height={this.props.videoHeight}
|
|
|
|
videoId={this.props.videoId}
|
|
|
|
width={this.props.videoWidth}
|
|
|
|
onLoad={this.handleVideoLoaded}
|
|
|
|
/>
|
|
|
|
</div>
|
2020-10-07 17:40:30 -04:00
|
|
|
) : (
|
|
|
|
<div
|
|
|
|
className="video-thumbnail"
|
|
|
|
onClick={this.handleShowVideo}
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
src={this.props.thumbnail}
|
|
|
|
style={{
|
|
|
|
width: `${this.props.thumbnailWidth}px` || 'auto',
|
|
|
|
height: `${this.props.thumbnailHeight}px` || 'auto'
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<a
|
|
|
|
onClick={this.handleShowVideo}
|
|
|
|
>
|
|
|
|
<div className="button">
|
|
|
|
{this.props.buttonMessage}
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoPreview.propTypes = {
|
|
|
|
buttonMessage: PropTypes.string.isRequired,
|
|
|
|
thumbnail: PropTypes.string.isRequired,
|
|
|
|
thumbnailHeight: PropTypes.string,
|
|
|
|
thumbnailWidth: PropTypes.string,
|
|
|
|
videoHeight: PropTypes.string,
|
|
|
|
videoId: PropTypes.string.isRequired,
|
|
|
|
videoWidth: PropTypes.string
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = VideoPreview;
|