diff --git a/packages/edit-site/src/components/header-edit-mode/document-actions/index.js b/packages/edit-site/src/components/header-edit-mode/document-actions/index.js index 5f14445ccefcd8..c4f70f8b9c8c1e 100644 --- a/packages/edit-site/src/components/header-edit-mode/document-actions/index.js +++ b/packages/edit-site/src/components/header-edit-mode/document-actions/index.js @@ -22,6 +22,7 @@ import { } from '@wordpress/icons'; import { useEntityRecord } from '@wordpress/core-data'; import { displayShortcut } from '@wordpress/keycodes'; +import { useState, useEffect, useRef } from '@wordpress/element'; /** * Internal dependencies @@ -51,6 +52,15 @@ function PageDocumentActions() { const { setHasPageContentLock } = useDispatch( editSiteStore ); + const [ hasEditedTemplate, setHasEditedTemplate ] = useState( false ); + const prevHasPageContentLock = useRef( false ); + useEffect( () => { + if ( prevHasPageContentLock.current && ! hasPageContentLock ) { + setHasEditedTemplate( true ); + } + prevHasPageContentLock.current = hasPageContentLock; + }, [ hasPageContentLock ] ); + if ( ! hasResolved ) { return null; } @@ -64,17 +74,23 @@ function PageDocumentActions() { } return hasPageContentLock ? ( - + { editedRecord.title } ) : ( setHasPageContentLock( true ) } /> ); } -function TemplateDocumentActions( { onBack } ) { +function TemplateDocumentActions( { className, onBack } ) { const { isLoaded, record, getTitle, icon } = useEditedEntityRecord(); if ( ! isLoaded ) { @@ -95,7 +111,11 @@ function TemplateDocumentActions( { onBack } ) { : __( 'template' ); return ( - + { sprintf( /* translators: %s: the entity being edited, like "template"*/ @@ -108,10 +128,12 @@ function TemplateDocumentActions( { onBack } ) { ); } -function BaseDocumentActions( { icon, children, onBack, isPage = false } ) { +function BaseDocumentActions( { className, icon, children, onBack } ) { const { open: openCommandCenter } = useDispatch( commandsStore ); return ( -
+
{ onBack && (