Skip to content

Commit

Permalink
Add uploading state to video block (#30837)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored Apr 15, 2021
1 parent 483a9db commit 9e6ee0a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/block-library/src/video/edit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
Expand All @@ -7,6 +12,7 @@ import {
Button,
Disabled,
PanelBody,
Spinner,
withNotices,
} from '@wordpress/components';
import {
Expand Down Expand Up @@ -43,6 +49,7 @@ function VideoEdit( {
isSelected,
noticeUI,
attributes,
className,
setAttributes,
insertBlocksAfter,
onReplace,
Expand All @@ -52,6 +59,7 @@ function VideoEdit( {
const videoPlayer = useRef();
const posterImageButton = useRef();
const { id, caption, controls, poster, src, tracks } = attributes;
const isTemporaryVideo = ! id && isBlobURL( src );
const mediaUpload = useSelect(
( select ) => select( blockEditorStore ).getSettings().mediaUpload
);
Expand Down Expand Up @@ -113,7 +121,13 @@ function VideoEdit( {
noticeOperations.createErrorNotice( message );
}

const blockProps = useBlockProps();
const classes = classnames( className, {
'is-transient': isTemporaryVideo,
} );

const blockProps = useBlockProps( {
className: classes,
} );

if ( ! src ) {
return (
Expand Down Expand Up @@ -235,6 +249,7 @@ function VideoEdit( {
<Tracks tracks={ tracks } />
</video>
</Disabled>
{ isTemporaryVideo && <Spinner /> }
{ ( ! RichText.isEmpty( caption ) || isSelected ) && (
<RichText
tagName="figcaption"
Expand Down
17 changes: 17 additions & 0 deletions packages/block-library/src/video/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
text-align: center;
}

.wp-block-video {
position: relative;

&.is-transient video {
opacity: 0.3;
}

// Shown while video is being uploaded
.components-spinner {
position: absolute;
top: 50%;
left: 50%;
margin-top: -9px;
margin-left: -9px;
}
}

.editor-video-poster-control {
.components-base-control__label {
display: block;
Expand Down

0 comments on commit 9e6ee0a

Please sign in to comment.