Skip to content

Commit

Permalink
Address more CR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed Nov 15, 2024
1 parent 3f3ac4f commit 1fc531f
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions packages/editor/src/components/post-featured-image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
Notice,
} from '@wordpress/components';
import { isBlobURL } from '@wordpress/blob';
import { useState, useRef } from '@wordpress/element';
import { useState, useRef, useEffect } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { useSelect, withDispatch, withSelect } from '@wordpress/data';
import {
Expand Down Expand Up @@ -106,6 +106,13 @@ function PostFeaturedImage( {
const [ isLoading, setIsLoading ] = useState( false );
const { getSettings } = useSelect( blockEditorStore );
const { mediaSourceUrl } = getMediaDetails( media, currentPostId );
const toggleFocusTimerRef = useRef();

useEffect( () => {
return () => {
clearTimeout( toggleFocusTimerRef.current );
};
}, [] );

function onDropFiles( filesList ) {
getSettings().mediaUpload( {
Expand Down Expand Up @@ -269,7 +276,12 @@ function PostFeaturedImage( {
className="editor-post-featured-image__action"
onClick={ () => {
onRemoveImage();
toggleRef.current.focus();
// The toggle button is rendered conditionally, we need
// to wait it is rendered before moving focus to it.
toggleFocusTimerRef.current =
setTimeout( () => {
toggleRef.current?.focus();
} );
} }
variant={
isMissingMedia
Expand All @@ -294,15 +306,10 @@ function PostFeaturedImage( {
}

const applyWithSelect = withSelect( ( select ) => {
const { getMedia, getPostType } = select( coreStore );
const { getMedia, getPostType, hasFinishedResolution } =
select( coreStore );
const { getCurrentPostId, getEditedPostAttribute } = select( editorStore );
const featuredImageId = getEditedPostAttribute( 'featured_media' );
const isRequestingFeaturedImageMedia =
!! featuredImageId &&
! select( coreStore ).hasFinishedResolution( 'getMedia', [
featuredImageId,
{ context: 'view' },
] );

return {
media: featuredImageId
Expand All @@ -311,7 +318,12 @@ const applyWithSelect = withSelect( ( select ) => {
currentPostId: getCurrentPostId(),
postType: getPostType( getEditedPostAttribute( 'type' ) ),
featuredImageId,
isRequestingFeaturedImageMedia,
isRequestingFeaturedImageMedia:
!! featuredImageId &&
! hasFinishedResolution( 'getMedia', [
featuredImageId,
{ context: 'view' },
] ),
};
} );

Expand Down

0 comments on commit 1fc531f

Please sign in to comment.