Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Jan 31, 2024
1 parent 1a166c7 commit 16b7fbf
Showing 1 changed file with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,24 @@ const TagsPanel = () => {
};

const MaybeTagsPanel = () => {
const { tags, isPostTypeSupported, areTagsFetched } = useSelect(
( select ) => {
const postType = select( editorStore ).getCurrentPostType();
const tagsTaxonomy = select( coreStore ).getTaxonomy( 'post_tag' );
const _isPostTypeSupported =
tagsTaxonomy &&
tagsTaxonomy.types.some( ( type ) => type === postType );
const _areTagsFetched = tagsTaxonomy !== undefined;
const _tags =
tagsTaxonomy &&
select( editorStore ).getEditedPostAttribute(
tagsTaxonomy.rest_base
);
return {
tags: _tags,
isPostTypeSupported: _isPostTypeSupported,
areTagsFetched: _areTagsFetched,
};
},
[]
);
const hasTags = tags && tags.length;
const { hasTags, isPostTypeSupported } = useSelect( ( select ) => {
const postType = select( editorStore ).getCurrentPostType();
const tagsTaxonomy = select( coreStore ).getTaxonomy( 'post_tag' );
const _isPostTypeSupported = tagsTaxonomy?.types?.includes( postType );
const areTagsFetched = tagsTaxonomy !== undefined;
const tags =
tagsTaxonomy &&
select( editorStore ).getEditedPostAttribute(
tagsTaxonomy.rest_base
);
return {
hasTags: !! tags?.length,
isPostTypeSupported: areTagsFetched && _isPostTypeSupported,
};
}, [] );
const [ hadTagsWhenOpeningThePanel ] = useState( hasTags );

if ( ! isPostTypeSupported || ! areTagsFetched ) {
if ( ! isPostTypeSupported ) {
return null;
}

Expand Down

0 comments on commit 16b7fbf

Please sign in to comment.