Skip to content

Commit

Permalink
use cleaner types
Browse files Browse the repository at this point in the history
  • Loading branch information
CGastrell committed Dec 16, 2024
1 parent d60ddc2 commit f532158
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
PLACEMENT_MEDIA_SOURCE_DROPDOWN,
} from './types';
import type { ImageResponse } from './hooks/use-ai-image';
import type { SelectState, EditorSelectors, CoreSelectors } from './types';
import type { EditorSelectors, CoreSelectors } from './types';

const debug = debugFactory( 'jetpack-ai:featured-image' );

Expand Down Expand Up @@ -87,19 +87,15 @@ 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: keyof SelectState ) => EditorSelectors ) => {
const isOpened =
select( 'core/editor' ).isEditorPanelOpened ??
select( 'core/edit-post' ).isEditorPanelOpened;
return isOpened;
},
[]
);
const isEditorPanelOpened = useSelect( ( select: ( store ) => EditorSelectors ) => {
const isOpened =
select( editorStore ).isEditorPanelOpened ?? select( 'core/edit-post' ).isEditorPanelOpened;
return isOpened;
}, [] );

const currentFeaturedMedia = useSelect(
( select: ( store: keyof SelectState ) => EditorSelectors & CoreSelectors ) => {
const mediaId = select( 'core/editor' )?.getEditedPostAttribute?.( 'featured_media' );
( select: ( store ) => EditorSelectors & CoreSelectors ) => {
const mediaId = select( editorStore )?.getEditedPostAttribute?.( 'featured_media' );
return mediaId ? select( 'core' )?.getMedia?.( mediaId as number ) : null;
},
[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,3 @@ export interface CoreSelectors {
source_url: string;
} | null;
}

export interface SelectState {
'core/editor': EditorSelectors;
'core/edit-post': EditorSelectors;
core: CoreSelectors;
}

0 comments on commit f532158

Please sign in to comment.