Skip to content

Commit

Permalink
use a single call for all editorStore selects
Browse files Browse the repository at this point in the history
  • Loading branch information
CGastrell committed Dec 17, 2024
1 parent f532158 commit 9d84ea9
Showing 1 changed file with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,22 @@ export default function FeaturedImage( {
);
const siteType = useSiteType();
const postContent = usePostContent();
const { postTitle, postFeaturedMedia } = useSelect( select => {
return {
postTitle: select( editorStore ).getEditedPostAttribute( 'title' ),
postFeaturedMedia: select( editorStore ).getEditedPostAttribute( 'featured_media' ),
};
}, [] );
const { postTitle, postFeaturedMedia, currentFeaturedMedia, isEditorPanelOpened } = useSelect(
( select: ( store ) => EditorSelectors & CoreSelectors ) => {
const featuredMediaId = select( editorStore ).getEditedPostAttribute( 'featured_media' );
return {
postTitle: select( editorStore ).getEditedPostAttribute( 'title' ),
postFeaturedMedia: featuredMediaId,
currentFeaturedMedia: featuredMediaId
? select( 'core' )?.getMedia?.( featuredMediaId as number )
: null,
isEditorPanelOpened:
select( editorStore ).isEditorPanelOpened ??
select( 'core/edit-post' ).isEditorPanelOpened,
};
},
[]
);
const { saveToMediaLibrary } = useSaveToMediaLibrary();
const { tracks } = useAnalytics();
const { recordEvent } = tracks;
Expand Down Expand Up @@ -87,19 +97,6 @@ export default function FeaturedImage( {
// https://github.com/WordPress/gutenberg/blob/fe4d8cb936df52945c01c1863f7b87b58b7cc69f/packages/edit-post/CHANGELOG.md?plain=1#L19
const toggleEditorPanelOpened =
toggleEditorPanelOpenedFromEditor ?? toggleEditorPanelOpenedFromEditPost;
const isEditorPanelOpened = useSelect( ( select: ( store ) => EditorSelectors ) => {
const isOpened =
select( editorStore ).isEditorPanelOpened ?? select( 'core/edit-post' ).isEditorPanelOpened;
return isOpened;
}, [] );

const currentFeaturedMedia = useSelect(
( select: ( store ) => EditorSelectors & CoreSelectors ) => {
const mediaId = select( editorStore )?.getEditedPostAttribute?.( 'featured_media' );
return mediaId ? select( 'core' )?.getMedia?.( mediaId as number ) : null;
},
[]
);

const {
pointer,
Expand Down

0 comments on commit 9d84ea9

Please sign in to comment.