Skip to content

Commit 35ba7ef

Browse files
Mamadukacarolinan
andauthored
Editor: Improve conditions for displaying new page assembler (#68852)
* Editor: Improve conditions for displaying new page assembler * Add note as inline comment Co-authored-by: Mamaduka <[email protected]> Co-authored-by: carolinan <[email protected]>
1 parent 73b8e2c commit 35ba7ef

File tree

1 file changed

+20
-12
lines changed
  • packages/editor/src/components/start-page-options

1 file changed

+20
-12
lines changed

packages/editor/src/components/start-page-options/index.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ import { store as interfaceStore } from '@wordpress/interface';
1212
import { store as editorStore } from '../../store';
1313

1414
export default function StartPageOptions() {
15-
const { postId, shouldEnable } = useSelect( ( select ) => {
16-
const {
17-
isEditedPostDirty,
18-
isEditedPostEmpty,
19-
getCurrentPostId,
20-
getCurrentPostType,
21-
} = select( editorStore );
15+
const { postId, enabled } = useSelect( ( select ) => {
16+
const { getCurrentPostId, getCurrentPostType } = select( editorStore );
2217
const preferencesModalActive =
2318
select( interfaceStore ).isModalActive( 'editor/preferences' );
2419
const choosePatternModalEnabled = select( preferencesStore ).get(
@@ -27,24 +22,37 @@ export default function StartPageOptions() {
2722
);
2823
return {
2924
postId: getCurrentPostId(),
30-
shouldEnable:
25+
enabled:
3126
choosePatternModalEnabled &&
3227
! preferencesModalActive &&
33-
! isEditedPostDirty() &&
34-
isEditedPostEmpty() &&
3528
'page' === getCurrentPostType(),
3629
};
3730
}, [] );
31+
const { isEditedPostDirty, isEditedPostEmpty } = useSelect( editorStore );
3832
const { setIsInserterOpened } = useDispatch( editorStore );
3933

4034
useEffect( () => {
41-
if ( shouldEnable ) {
35+
if ( ! enabled ) {
36+
return;
37+
}
38+
39+
const isFreshPage = ! isEditedPostDirty() && isEditedPostEmpty();
40+
if ( isFreshPage ) {
4241
setIsInserterOpened( {
4342
tab: 'patterns',
4443
category: 'core/starter-content',
4544
} );
4645
}
47-
}, [ postId, shouldEnable, setIsInserterOpened ] );
46+
47+
// Note: The `postId` ensures the effect re-runs when pages are switched without remounting the component.
48+
// Examples: changing pages in the List View, creating a new page via Command Palette.
49+
}, [
50+
postId,
51+
enabled,
52+
setIsInserterOpened,
53+
isEditedPostDirty,
54+
isEditedPostEmpty,
55+
] );
4856

4957
return null;
5058
}

0 commit comments

Comments
 (0)