Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import {
chevronLeftSmall as chevronLeftSmallIcon,
page as pageIcon,
} from '@wordpress/icons';
import { useEntityRecord } from '@wordpress/core-data';
import { displayShortcut } from '@wordpress/keycodes';
import { useState, useEffect, useRef } from '@wordpress/element';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand All @@ -36,20 +36,30 @@ export default function DocumentActions() {
}

function PageDocumentActions() {
const { hasPageContentFocus, context } = useSelect(
( select ) => ( {
hasPageContentFocus: select( editSiteStore ).hasPageContentFocus(),
context: select( editSiteStore ).getEditedPostContext(),
} ),
const { hasPageContentFocus, hasResolved, isFound, title } = useSelect(
( select ) => {
const {
hasPageContentFocus: _hasPageContentFocus,
getEditedPostContext,
} = select( editSiteStore );
const { getEditedEntityRecord, hasFinishedResolution } =
select( coreStore );
const context = getEditedPostContext();
const queryArgs = [ 'postType', context.postType, context.postId ];
const page = getEditedEntityRecord( ...queryArgs );
return {
hasPageContentFocus: _hasPageContentFocus(),
hasResolved: hasFinishedResolution(
'getEditedEntityRecord',
queryArgs
),
isFound: !! page,
title: page?.title,
};
},
[]
);

const { hasResolved, editedRecord } = useEntityRecord(
'postType',
context.postType,
context.postId
);

const { setHasPageContentFocus } = useDispatch( editSiteStore );

const [ hasEditedTemplate, setHasEditedTemplate ] = useState( false );
Expand All @@ -65,7 +75,7 @@ function PageDocumentActions() {
return null;
}

if ( ! editedRecord ) {
if ( ! isFound ) {
return (
<div className="edit-site-document-actions">
{ __( 'Document not found' ) }
Expand All @@ -80,7 +90,7 @@ function PageDocumentActions() {
} ) }
icon={ pageIcon }
>
{ editedRecord.title }
{ title }
</BaseDocumentActions>
) : (
<TemplateDocumentActions
Expand Down