diff --git a/packages/edit-post/src/components/header/fullscreen-mode-close/index.js b/packages/edit-post/src/components/header/fullscreen-mode-close/index.js
index a6445a1982dd2f..04054390374796 100644
--- a/packages/edit-post/src/components/header/fullscreen-mode-close/index.js
+++ b/packages/edit-post/src/components/header/fullscreen-mode-close/index.js
@@ -24,7 +24,7 @@ import { useReducedMotion } from '@wordpress/compose';
*/
import { store as editPostStore } from '../../../store';
-function FullscreenModeClose( { showTooltip, icon, href } ) {
+function FullscreenModeClose( { showTooltip, icon, href, initialPost } ) {
const { isActive, isRequestingSiteIcon, postType, siteIconUrl } = useSelect(
( select ) => {
const { getCurrentPostType } = select( editorStore );
@@ -33,7 +33,7 @@ function FullscreenModeClose( { showTooltip, icon, href } ) {
select( coreStore );
const siteData =
getEntityRecord( 'root', '__unstableBase', undefined ) || {};
-
+ const _postType = initialPost?.type || getCurrentPostType();
return {
isActive: isFeatureActive( 'fullscreenMode' ),
isRequestingSiteIcon: isResolving( 'getEntityRecord', [
@@ -41,7 +41,7 @@ function FullscreenModeClose( { showTooltip, icon, href } ) {
'__unstableBase',
undefined,
] ),
- postType: getPostType( getCurrentPostType() ),
+ postType: getPostType( _postType ),
siteIconUrl: siteData.site_icon_url,
};
},
@@ -88,17 +88,20 @@ function FullscreenModeClose( { showTooltip, icon, href } ) {
'has-icon': siteIconUrl,
} );
+ const buttonHref =
+ href ??
+ addQueryArgs( 'edit.php', {
+ post_type: postType.slug,
+ } );
+
+ const buttonLabel = postType?.labels?.view_items ?? __( 'Back' );
+
return (
}
editorNotices={ }
diff --git a/packages/edit-post/src/editor.js b/packages/edit-post/src/editor.js
index 99039a7d786313..ce99ed1eef38eb 100644
--- a/packages/edit-post/src/editor.js
+++ b/packages/edit-post/src/editor.js
@@ -32,10 +32,8 @@ function Editor( {
initialEdits,
...props
} ) {
- const { currentPost, getPostLinkProps, goBack } = usePostHistory(
- initialPostId,
- initialPostType
- );
+ const { currentPost, getPostLinkProps, initialPost, goBack } =
+ usePostHistory( initialPostId, initialPostType );
const { hasInlineToolbar, post, preferredStyleVariations, template } =
useSelect(
@@ -80,8 +78,8 @@ function Editor( {
const defaultRenderingMode =
currentPost.postType === 'wp_template' ? 'all' : 'post-only';
- const editorSettings = useMemo( () => {
- const result = {
+ const editorSettings = useMemo(
+ () => ( {
...settings,
getPostLinkProps,
goBack,
@@ -91,17 +89,17 @@ function Editor( {
onChange: updatePreferredStyleVariations,
},
hasInlineToolbar,
- };
- return result;
- }, [
- settings,
- hasInlineToolbar,
- preferredStyleVariations,
- updatePreferredStyleVariations,
- getPostLinkProps,
- goBack,
- defaultRenderingMode,
- ] );
+ } ),
+ [
+ settings,
+ hasInlineToolbar,
+ preferredStyleVariations,
+ updatePreferredStyleVariations,
+ getPostLinkProps,
+ goBack,
+ defaultRenderingMode,
+ ]
+ );
if ( ! post ) {
return null;
@@ -120,7 +118,7 @@ function Editor( {
-
+
diff --git a/packages/edit-post/src/hooks/use-post-history.js b/packages/edit-post/src/hooks/use-post-history.js
index fe7252b7d270d5..fa76258a0c2468 100644
--- a/packages/edit-post/src/hooks/use-post-history.js
+++ b/packages/edit-post/src/hooks/use-post-history.js
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
-import { useCallback, useReducer } from '@wordpress/element';
+import { useCallback, useReducer, useMemo } from '@wordpress/element';
import { addQueryArgs, getQueryArgs, removeQueryArgs } from '@wordpress/url';
/**
@@ -35,6 +35,13 @@ export default function usePostHistory( initialPostId, initialPostType ) {
[ { postId: initialPostId, postType: initialPostType } ]
);
+ const initialPost = useMemo( () => {
+ return {
+ type: initialPostType,
+ id: initialPostId,
+ };
+ }, [ initialPostType, initialPostId ] );
+
const getPostLinkProps = useCallback( ( params ) => {
const currentArgs = getQueryArgs( window.location.href );
const currentUrlWithoutArgs = removeQueryArgs(
@@ -68,6 +75,7 @@ export default function usePostHistory( initialPostId, initialPostType ) {
return {
currentPost,
getPostLinkProps,
+ initialPost,
goBack: postHistory.length > 1 ? goBack : undefined,
};
}