Skip to content

Commit

Permalink
chore: move poster methods to its file
Browse files Browse the repository at this point in the history
  • Loading branch information
up1512001 committed Nov 15, 2024
1 parent 7c97a35 commit a631118
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
10 changes: 0 additions & 10 deletions packages/block-library/src/video/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ function VideoEdit( {
} ) {
const instanceId = useInstanceId( VideoEdit );
const videoPlayer = useRef();
const posterImageButton = useRef();
const { id, controls, poster, src, tracks } = attributes;
const [ temporaryURL, setTemporaryURL ] = useState( attributes.blob );
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
Expand Down Expand Up @@ -174,13 +173,6 @@ function VideoEdit( {
);
}

function onRemovePoster() {
setAttributes( { poster: undefined } );

// Move focus back to the Media Upload button.
posterImageButton.current.focus();
}

return (
<>
{ isSingleSelected && (
Expand Down Expand Up @@ -230,8 +222,6 @@ function VideoEdit( {
<PosterImage
poster={ poster }
setAttributes={ setAttributes }
posterImageButton={ posterImageButton }
onRemovePoster={ onRemovePoster }
instanceId={ instanceId }
/>
</ToolsPanel>
Expand Down
17 changes: 10 additions & 7 deletions packages/block-library/src/video/poster-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ import {
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { useRef } from '@wordpress/element';

function PosterImage( {
poster,
setAttributes,
posterImageButton,
onRemovePoster,
instanceId,
} ) {
function PosterImage( { poster, setAttributes, instanceId } ) {
const posterImageButton = useRef();
const VIDEO_POSTER_ALLOWED_MEDIA_TYPES = [ 'image' ];

const videoPosterDescription = `video-block__poster-image-description-${ instanceId }`;
Expand All @@ -24,6 +20,13 @@ function PosterImage( {
setAttributes( { poster: image.url } );
}

function onRemovePoster() {
setAttributes( { poster: undefined } );

// Move focus back to the Media Upload button.
posterImageButton.current.focus();
}

return (
<ToolsPanelItem
label={ __( 'Poster image' ) }
Expand Down

0 comments on commit a631118

Please sign in to comment.