Skip to content

Commit

Permalink
Address CR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed Nov 14, 2024
1 parent 0bb386c commit 47d9230
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions packages/editor/src/components/post-featured-image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function PostFeaturedImage( {
postType,
noticeUI,
noticeOperations,
isRequestingFeaturedImageMedia,
} ) {
const toggleRef = useRef();
const [ isLoading, setIsLoading ] = useState( false );
Expand Down Expand Up @@ -155,23 +156,7 @@ function PostFeaturedImage( {
);
}

const { isRequestingFeaturedImageMedia } = useSelect(
( select ) => {
const _isRequestingFeaturedImageMedia =
!! featuredImageId &&
! select( coreStore ).hasFinishedResolution( 'getMedia', [
featuredImageId,
{ context: 'view' },
] );

return {
isRequestingFeaturedImageMedia: _isRequestingFeaturedImageMedia,
};
},
[ featuredImageId ]
);

const noImageData =
const isMissingMedia =
! isRequestingFeaturedImageMedia && !! featuredImageId && ! media;

return (
Expand All @@ -198,7 +183,7 @@ function PostFeaturedImage( {
modalClass="editor-post-featured-image__media-modal"
render={ ( { open } ) => (
<div className="editor-post-featured-image__container">
{ noImageData ? (
{ isMissingMedia ? (
<p>
{ __(
'Could not retrieve the featured image data.'
Expand Down Expand Up @@ -256,7 +241,7 @@ function PostFeaturedImage( {
'editor-post-featured-image__actions',
{
'editor-post-featured-image__actions-missing-image':
noImageData,
isMissingMedia,
'editor-post-featured-image__actions-is-requesting-image':
isRequestingFeaturedImageMedia,
}
Expand All @@ -268,7 +253,7 @@ function PostFeaturedImage( {
onClick={ open }
aria-haspopup="dialog"
variant={
noImageData
isMissingMedia
? 'secondary'
: undefined
}
Expand All @@ -283,11 +268,11 @@ function PostFeaturedImage( {
toggleRef.current.focus();
} }
variant={
noImageData
isMissingMedia
? 'secondary'
: undefined
}
isDestructive={ noImageData }
isDestructive={ isMissingMedia }
>
{ __( 'Remove' ) }
</Button>
Expand All @@ -308,6 +293,12 @@ const applyWithSelect = withSelect( ( select ) => {
const { getMedia, getPostType } = 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 @@ -316,6 +307,7 @@ const applyWithSelect = withSelect( ( select ) => {
currentPostId: getCurrentPostId(),
postType: getPostType( getEditedPostAttribute( 'type' ) ),
featuredImageId,
isRequestingFeaturedImageMedia,
};
} );

Expand Down

0 comments on commit 47d9230

Please sign in to comment.