Skip to content

Commit

Permalink
Additional tweaks/optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZebulanStanphill committed Oct 19, 2020
1 parent ea7bbc7 commit 0130246
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions packages/editor/src/components/post-format/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,41 @@ export default function PostFormat() {
const instanceId = useInstanceId( PostFormat );
const postFormatSelectorId = `post-format-selector-${ instanceId }`;

const { postFormat, suggestedFormat, supportedFormats } = useSelect(
const { currentFormat, suggestedFormat, supportedFormats } = useSelect(
( select ) => {
const themeSupportedFormats =
select( 'core' ).getThemeSupports().formats ?? [];
const { getEditedPostAttribute, getSuggestedPostFormat } = select(
'core/editor'
);
const _postFormat = getEditedPostAttribute( 'format' );
const _currentFormat =
getEditedPostAttribute( 'format' ) ?? 'standard';

// Ensure current format is always in the set.
// The current format may not be a format supported by the theme.
const _supportedFormats = union(
[ _postFormat ],
[ _currentFormat ],
themeSupportedFormats
);

// The suggested format may not be supported by the theme, so we have
// to check to make sure.
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.
let supportedSuggestedFormat = null;

if (
potentialSuggestedFormat &&
potentialSuggestedFormat !== _currentFormat &&
_supportedFormats.includes( potentialSuggestedFormat )
) {
supportedSuggestedFormat = potentialSuggestedFormat;
}

return {
postFormat: _postFormat ?? 'standard',
currentFormat: _currentFormat,
supportedFormats: _supportedFormats,
suggestedFormat: supportedSuggestedFormat,
};
Expand All @@ -83,7 +87,7 @@ export default function PostFormat() {
{ __( 'Post Format' ) }
</label>
<SelectControl
value={ postFormat }
value={ currentFormat }
onChange={ updatePostFormat }
id={ postFormatSelectorId }
options={ supportedFormats.map( ( format ) => ( {
Expand All @@ -93,7 +97,7 @@ export default function PostFormat() {
/>
</div>

{ suggestedFormat && suggestedFormat !== postFormat && (
{ suggestedFormat && (
<div className="editor-post-format__suggestion">
{ __( 'Suggestion:' ) }{ ' ' }
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function PostFormatPanel() {
const potentialSuggestedFormat = getSuggestedPostFormat();

// If the suggested format isn't null, isn't already applied, and is
// supported by the theme, return it.
// supported by the theme, return it. Otherwise, return null.
if (
potentialSuggestedFormat &&
potentialSuggestedFormat !== currentFormat &&
Expand Down

0 comments on commit 0130246

Please sign in to comment.