mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-28 01:56:00 -05:00
Add spinner while video is still loading
This commit is contained in:
parent
3ed2ed1447
commit
e14b6d52f3
3 changed files with 43 additions and 9 deletions
|
@ -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 {
|
||||||
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 {
|
||||||
<div className="video-preview">
|
<div className="video-preview">
|
||||||
{this.state.videoOpen ?
|
{this.state.videoOpen ?
|
||||||
(
|
(
|
||||||
<Video
|
<div className="spinner-video-container">
|
||||||
className="video"
|
{this.state.spinnerVisible ? <Spinner className="loading-spinner" /> : null}
|
||||||
height={this.props.videoHeight}
|
<Video
|
||||||
videoId={this.props.videoId}
|
className="video"
|
||||||
width={this.props.videoWidth}
|
height={this.props.videoHeight}
|
||||||
/>
|
videoId={this.props.videoId}
|
||||||
|
width={this.props.videoWidth}
|
||||||
|
onLoad={this.handleVideoLoaded}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div
|
<div
|
||||||
className="video-thumbnail"
|
className="video-thumbnail"
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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 = {
|
||||||
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;
|
||||||
|
|
Loading…
Reference in a new issue