Skip to content

Commit

Permalink
Pass postId to the pageTypeBadge hook, for use outside editor
Browse files Browse the repository at this point in the history
  • Loading branch information
louwie17 committed Dec 4, 2024
1 parent 1bdc379 commit 031625d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
4 changes: 3 additions & 1 deletion packages/editor/src/components/document-bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const MotionButton = motion( Button );
*/
export default function DocumentBar( props ) {
const {
postId,
postType,
postTypeLabel,
documentTitle,
Expand Down Expand Up @@ -93,6 +94,7 @@ export default function DocumentBar( props ) {
const _postTypeLabel = getPostType( _postType )?.labels?.singular_name;

return {
postId: _postId,
postType: _postType,
postTypeLabel: _postTypeLabel,
documentTitle: _document.title,
Expand Down Expand Up @@ -120,7 +122,7 @@ export default function DocumentBar( props ) {
const title = props.title || entityTitle;
const icon = props.icon;

const pageTypeBadge = usePageTypeBadge();
const pageTypeBadge = usePageTypeBadge( postId );

const mountedRef = useRef( false );
useEffect( () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/components/post-card-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function PostCardPanel( {
[ postId, postType ]
);

const pageTypeBadge = usePageTypeBadge();
const pageTypeBadge = usePageTypeBadge( parseInt( postId, 10 ) );

return (
<div className="editor-post-card-panel">
Expand Down
11 changes: 3 additions & 8 deletions packages/editor/src/utils/pageTypeBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
*/
import { store as editorStore } from '../store';

/**
* Custom hook to get the page type badge for the current post on edit site view.
*
* @param {number} postId postId of the current post being edited.
*/
export default function usePageTypeBadge() {
export default function usePageTypeBadge( postId ) {
const { isFrontPage, isPostsPage } = useSelect( ( select ) => {
const { getCurrentPostId } = select( editorStore );
const { canUser, getEditedEntityRecord } = select( coreStore );
const postId = getCurrentPostId();
const siteSettings = canUser( 'read', {
kind: 'root',
name: 'site',
Expand Down

0 comments on commit 031625d

Please sign in to comment.