Skip to content

Commit

Permalink
MaybePostFormatPanel logic optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZebulanStanphill committed Jul 22, 2020
1 parent 43aa4c1 commit 831ddf7
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,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 831ddf7

Please sign in to comment.