From c898a6ae415ae3ba62f4ce6232cdb70d781da287 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 23 Jan 2025 18:12:34 +0400 Subject: [PATCH 1/2] Editor: Improve conditions for displaying new page assembler --- .../components/start-page-options/index.js | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/editor/src/components/start-page-options/index.js b/packages/editor/src/components/start-page-options/index.js index d7874000ffc42..4b9c845b494ab 100644 --- a/packages/editor/src/components/start-page-options/index.js +++ b/packages/editor/src/components/start-page-options/index.js @@ -12,13 +12,8 @@ import { store as interfaceStore } from '@wordpress/interface'; import { store as editorStore } from '../../store'; export default function StartPageOptions() { - const { postId, shouldEnable } = useSelect( ( select ) => { - const { - isEditedPostDirty, - isEditedPostEmpty, - getCurrentPostId, - getCurrentPostType, - } = select( editorStore ); + const { postId, enabled } = useSelect( ( select ) => { + const { getCurrentPostId, getCurrentPostType } = select( editorStore ); const preferencesModalActive = select( interfaceStore ).isModalActive( 'editor/preferences' ); const choosePatternModalEnabled = select( preferencesStore ).get( @@ -27,24 +22,34 @@ export default function StartPageOptions() { ); return { postId: getCurrentPostId(), - shouldEnable: + enabled: choosePatternModalEnabled && ! preferencesModalActive && - ! isEditedPostDirty() && - isEditedPostEmpty() && 'page' === getCurrentPostType(), }; }, [] ); + const { isEditedPostDirty, isEditedPostEmpty } = useSelect( editorStore ); const { setIsInserterOpened } = useDispatch( editorStore ); useEffect( () => { - if ( shouldEnable ) { + if ( ! enabled ) { + return; + } + + const isFreshPage = ! isEditedPostDirty() && isEditedPostEmpty(); + if ( isFreshPage ) { setIsInserterOpened( { tab: 'patterns', category: 'core/starter-content', } ); } - }, [ postId, shouldEnable, setIsInserterOpened ] ); + }, [ + postId, + enabled, + setIsInserterOpened, + isEditedPostDirty, + isEditedPostEmpty, + ] ); return null; } From 8ab183c04f832c5e0429f13f1369c15ebc8e8c80 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Mon, 27 Jan 2025 10:48:10 +0400 Subject: [PATCH 2/2] Add note as inline comment --- packages/editor/src/components/start-page-options/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/editor/src/components/start-page-options/index.js b/packages/editor/src/components/start-page-options/index.js index 4b9c845b494ab..54d956ff06e7c 100644 --- a/packages/editor/src/components/start-page-options/index.js +++ b/packages/editor/src/components/start-page-options/index.js @@ -43,6 +43,9 @@ export default function StartPageOptions() { category: 'core/starter-content', } ); } + + // Note: The `postId` ensures the effect re-runs when pages are switched without remounting the component. + // Examples: changing pages in the List View, creating a new page via Command Palette. }, [ postId, enabled,