Skip to content

Commit

Permalink
Don't re-open the starter content modal after closing Preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Feb 17, 2025
1 parent d9e990b commit 91078a2
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/editor/src/components/start-page-options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,34 +142,39 @@ function StartPageOptionsModal( { onClose } ) {
export default function StartPageOptions() {
const [ isOpen, setIsOpen ] = useState( false );
const { isEditedPostDirty, isEditedPostEmpty } = useSelect( editorStore );
const { isModalActive } = useSelect( interfaceStore );
const { enabled, postId } = useSelect( ( select ) => {
const { getCurrentPostId, getCurrentPostType } = select( editorStore );
const preferencesModalActive =
select( interfaceStore ).isModalActive( 'editor/preferences' );
const choosePatternModalEnabled = select( preferencesStore ).get(
'core',
'enableChoosePatternModal'
);
return {
postId: getCurrentPostId(),
enabled:
choosePatternModalEnabled &&
! preferencesModalActive &&
'page' === getCurrentPostType(),
choosePatternModalEnabled && 'page' === getCurrentPostType(),
};
}, [] );

// 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.
useEffect( () => {
const isFreshPage = ! isEditedPostDirty() && isEditedPostEmpty();
if ( ! enabled || ! isFreshPage ) {
// Prevents immediately opening when features is enabled via preferences modal.
const isPreferencesModalActive = isModalActive( 'editor/preferences' );
if ( ! enabled || ! isFreshPage || isPreferencesModalActive ) {
return;
}

// Open the modal after the initial render for a new page.
setIsOpen( true );
}, [ enabled, postId, isEditedPostDirty, isEditedPostEmpty ] );
}, [
enabled,
postId,
isEditedPostDirty,
isEditedPostEmpty,
isModalActive,
] );

if ( ! isOpen ) {
return null;
Expand Down

0 comments on commit 91078a2

Please sign in to comment.