Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video Block: refactor setting panel #67044

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: move poster methods to its file
  • Loading branch information
up1512001 committed Nov 15, 2024
commit a631118355eca9059453edd46edfa56120c0793e
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
Loading