Skip to content

Commit

Permalink
Site Editor: Remove useEditedEntityRecord hook (#66955)
Browse files Browse the repository at this point in the history
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: mcsf <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
  • Loading branch information
4 people authored Nov 13, 2024
1 parent f992ba7 commit cbaeee2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 73 deletions.
7 changes: 5 additions & 2 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,15 @@ export default function EditSiteEditor( { isPostsList = false } ) {
hasSiteIcon: !! siteData?.site_icon_url,
};
}, [] );
useEditorTitle();
const postWithTemplate = !! contextPostId;
useEditorTitle(
postWithTemplate ? contextPostType : editedPostType,
postWithTemplate ? contextPostId : editedPostId
);
const _isPreviewingTheme = isPreviewingTheme();
const hasDefaultEditorCanvasView = ! useHasEditorCanvasContainer();
const iframeProps = useEditorIframeProps();
const isEditMode = canvas === 'edit';
const postWithTemplate = !! contextPostId;
const loadingProgressId = useInstanceId(
CanvasLoader,
'edit-site-editor__loading-progress'
Expand Down
50 changes: 37 additions & 13 deletions packages/edit-site/src/components/editor/use-editor-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,58 @@
* WordPress dependencies
*/
import { _x, sprintf } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { store as editorStore } from '@wordpress/editor';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
*/
import useEditedEntityRecord from '../use-edited-entity-record';
import useTitle from '../routes/use-title';
import { POST_TYPE_LABELS, TEMPLATE_POST_TYPE } from '../../utils/constants';

function useEditorTitle() {
const {
record: editedPost,
getTitle,
isLoaded: hasLoadedPost,
} = useEditedEntityRecord();
let title;
if ( hasLoadedPost ) {
title = sprintf(
function useEditorTitle( postType, postId ) {
const { title, isLoaded } = useSelect(
( select ) => {
const { getEditedEntityRecord, hasFinishedResolution } =
select( coreStore );
const { __experimentalGetTemplateInfo: getTemplateInfo } =
select( editorStore );
const _record = getEditedEntityRecord(
'postType',
postType,
postId
);
const _isLoaded = hasFinishedResolution( 'getEditedEntityRecord', [
'postType',
postType,
postId,
] );
const templateInfo = getTemplateInfo( _record );

return {
title: templateInfo.title,
isLoaded: _isLoaded,
};
},
[ postType, postId ]
);

let editorTitle;
if ( isLoaded ) {
editorTitle = sprintf(
// translators: A breadcrumb trail for the Admin document title. 1: title of template being edited, 2: type of template (Template or Template Part).
_x( '%1$s ‹ %2$s', 'breadcrumb trail' ),
getTitle(),
POST_TYPE_LABELS[ editedPost.type ] ??
decodeEntities( title ),
POST_TYPE_LABELS[ postType ] ??
POST_TYPE_LABELS[ TEMPLATE_POST_TYPE ]
);
}

// Only announce the title once the editor is ready to prevent "Replace"
// action in <URLQueryController> from double-announcing.
useTitle( hasLoadedPost && title );
useTitle( isLoaded && editorTitle );
}

export default useEditorTitle;

This file was deleted.

0 comments on commit cbaeee2

Please sign in to comment.