Skip to content

Commit

Permalink
MaybePostFormatPanel logic optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZebulanStanphill committed Oct 19, 2020
1 parent ffa57e9 commit 19dab45
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,19 @@ const PostFormatSuggestion = ( { onApplySuggestion, suggestionText } ) => (

export default function PostFormatPanel() {
const suggestedFormat = useSelect( ( select ) => {
const supportedFormats =
select( 'core' ).getThemeSupports().formats ?? [];
const { getEditedPostAttribute, getSuggestedPostFormat } = select(
'core/editor'
);
const currentFormat = getEditedPostAttribute( 'format' );
const potentialSuggestedFormat = getSuggestedPostFormat();

// If the suggested format isn't null, isn't already applied, and is
// supported by the theme, return it. Otherwise, return null.
if (
potentialSuggestedFormat &&
potentialSuggestedFormat !== currentFormat &&
supportedFormats.includes( potentialSuggestedFormat )
potentialSuggestedFormat !== getEditedPostAttribute( 'format' ) &&
( select( 'core' ).getThemeSupports().formats ?? [] ).includes(
potentialSuggestedFormat
)
) {
return potentialSuggestedFormat;
}
Expand Down

0 comments on commit 19dab45

Please sign in to comment.