Commit e14b6d52 authored by Karishma Chadha's avatar Karishma Chadha

Add spinner while video is still loading

parent 3ed2ed14
...@@ -3,6 +3,7 @@ const PropTypes = require('prop-types'); ...@@ -3,6 +3,7 @@ const PropTypes = require('prop-types');
const React = require('react'); const React = require('react');
const Video = require('../video/video.jsx'); const Video = require('../video/video.jsx');
const Spinner = require('../spinner/spinner.jsx');
require('./video-preview.scss'); require('./video-preview.scss');
...@@ -10,16 +11,25 @@ class VideoPreview extends React.Component { ...@@ -10,16 +11,25 @@ class VideoPreview extends React.Component {
constructor (props) { constructor (props) {
super(props); super(props);
bindAll(this, [ bindAll(this, [
'handleShowVideo' 'handleShowVideo',
'handleVideoLoaded'
]); ]);
this.state = { this.state = {
videoOpen: false videoOpen: false,
spinnerVisible: false
}; };
} }
handleShowVideo () { handleShowVideo () {
this.setState({videoOpen: true}); this.setState({
videoOpen: true,
spinnerVisible: true
});
}
handleVideoLoaded () {
this.setState({spinnerVisible: false});
} }
render () { render () {
...@@ -27,12 +37,16 @@ class VideoPreview extends React.Component { ...@@ -27,12 +37,16 @@ class VideoPreview extends React.Component {
<div className="video-preview"> <div className="video-preview">
{this.state.videoOpen ? {this.state.videoOpen ?
( (
<div className="spinner-video-container">
{this.state.spinnerVisible ? <Spinner className="loading-spinner" /> : null}
<Video <Video
className="video" className="video"
height={this.props.videoHeight} height={this.props.videoHeight}
videoId={this.props.videoId} videoId={this.props.videoId}
width={this.props.videoWidth} width={this.props.videoWidth}
onLoad={this.handleVideoLoaded}
/> />
</div>
) : ( ) : (
<div <div
className="video-thumbnail" className="video-thumbnail"
......
...@@ -24,3 +24,20 @@ ...@@ -24,3 +24,20 @@
margin-top: 20px; margin-top: 20px;
} }
} }
.loading-spinner {
margin: auto;
width: 5rem;
height: 5rem;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
.spinner-video-container {
width: 100%;
height: 100%;
position: relative;
}
\ No newline at end of file
...@@ -16,6 +16,7 @@ const Video = props => ( ...@@ -16,6 +16,7 @@ const Video = props => (
src={`https://fast.wistia.net/embed/iframe/${props.videoId}?seo=false&videoFoam=true`} src={`https://fast.wistia.net/embed/iframe/${props.videoId}?seo=false&videoFoam=true`}
title={props.title} title={props.title}
width={props.width} width={props.width}
onLoad={props.onLoad}
/> />
<script <script
async async
...@@ -32,9 +33,11 @@ Video.defaultProps = { ...@@ -32,9 +33,11 @@ Video.defaultProps = {
Video.propTypes = { Video.propTypes = {
className: PropTypes.string, className: PropTypes.string,
height: PropTypes.string.isRequired, height: PropTypes.string.isRequired,
onLoad: PropTypes.func,
title: PropTypes.string.isRequired, title: PropTypes.string.isRequired,
videoId: PropTypes.string.isRequired, videoId: PropTypes.string.isRequired,
width: PropTypes.string.isRequired width: PropTypes.string.isRequired
}; };
module.exports = Video; module.exports = Video;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment