Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions packages/block-library/src/audio/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,19 @@ function AudioEdit( {
className,
setAttributes,
onReplace,
isSelected,
isSelected: isSingleSelected,
insertBlocksAfter,
} ) {
const { id, autoplay, loop, preload, src } = attributes;
const isTemporaryAudio = ! id && isBlobURL( src );
const { mediaUpload, multiAudioSelection } = useSelect( ( select ) => {
const { getSettings, getMultiSelectedBlockClientIds, getBlockName } =
select( blockEditorStore );
const multiSelectedClientIds = getMultiSelectedBlockClientIds();

return {
mediaUpload: getSettings().mediaUpload,
multiAudioSelection:
multiSelectedClientIds.length &&
multiSelectedClientIds.every(
( _clientId ) => getBlockName( _clientId ) === 'core/audio'
),
};
}, [] );
const { getSettings } = useSelect( blockEditorStore );

useEffect( () => {
if ( ! id && isBlobURL( src ) ) {
const file = getBlobByURL( src );

if ( file ) {
mediaUpload( {
getSettings().mediaUpload( {
filesList: [ file ],
onFileChange: ( [ media ] ) => onSelectAudio( media ),
onError: ( e ) => onUploadError( e ),
Expand Down Expand Up @@ -156,7 +143,7 @@ function AudioEdit( {

return (
<>
{ ! multiAudioSelection && (
{ isSingleSelected && (
<BlockControls group="other">
<MediaReplaceFlow
mediaId={ id }
Expand Down Expand Up @@ -212,17 +199,17 @@ function AudioEdit( {
so the user clicking on it won't play the
file or change the position slider when the controls are enabled.
*/ }
<Disabled isDisabled={ ! isSelected }>
<Disabled isDisabled={ ! isSingleSelected }>
<audio controls="controls" src={ src } />
</Disabled>
{ isTemporaryAudio && <Spinner /> }
<Caption
attributes={ attributes }
setAttributes={ setAttributes }
isSelected={ isSelected }
isSelected={ isSingleSelected }
insertBlocksAfter={ insertBlocksAfter }
label={ __( 'Audio caption text' ) }
showToolbarButton={ ! multiAudioSelection }
showToolbarButton={ isSingleSelected }
/>
</figure>
</>
Expand Down
27 changes: 7 additions & 20 deletions packages/block-library/src/video/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const ALLOWED_MEDIA_TYPES = [ 'video' ];
const VIDEO_POSTER_ALLOWED_MEDIA_TYPES = [ 'image' ];

function VideoEdit( {
isSelected,
isSelected: isSingleSelected,
attributes,
className,
setAttributes,
Expand All @@ -75,26 +75,13 @@ function VideoEdit( {
const posterImageButton = useRef();
const { id, controls, poster, src, tracks } = attributes;
const isTemporaryVideo = ! id && isBlobURL( src );
const { mediaUpload, multiVideoSelection } = useSelect( ( select ) => {
const { getSettings, getMultiSelectedBlockClientIds, getBlockName } =
select( blockEditorStore );
const multiSelectedClientIds = getMultiSelectedBlockClientIds();

return {
mediaUpload: getSettings().mediaUpload,
multiVideoSelection:
multiSelectedClientIds.length &&
multiSelectedClientIds.every(
( _clientId ) => getBlockName( _clientId ) === 'core/video'
),
};
}, [] );
const { getSettings } = useSelect( blockEditorStore );

useEffect( () => {
if ( ! id && isBlobURL( src ) ) {
const file = getBlobByURL( src );
if ( file ) {
mediaUpload( {
getSettings().mediaUpload( {
filesList: [ file ],
onFileChange: ( [ media ] ) => onSelectVideo( media ),
onError: onUploadError,
Expand Down Expand Up @@ -195,7 +182,7 @@ function VideoEdit( {

return (
<>
{ ! multiVideoSelection && (
{ isSingleSelected && (
<>
<BlockControls>
<TracksEditor
Expand Down Expand Up @@ -281,7 +268,7 @@ function VideoEdit( {
so the user clicking on it won't play the
video when the controls are enabled.
*/ }
<Disabled isDisabled={ ! isSelected }>
<Disabled isDisabled={ ! isSingleSelected }>
<video
controls={ controls }
poster={ poster }
Expand All @@ -295,10 +282,10 @@ function VideoEdit( {
<Caption
attributes={ attributes }
setAttributes={ setAttributes }
isSelected={ isSelected }
isSelected={ isSingleSelected }
insertBlocksAfter={ insertBlocksAfter }
label={ __( 'Video caption text' ) }
showToolbarButton={ ! multiVideoSelection }
showToolbarButton={ isSingleSelected }
/>
</figure>
</>
Expand Down