Skip to content

Commit

Permalink
Revert "Edit Post: Remove unnecessary effect in InitPatternModal (Wor…
Browse files Browse the repository at this point in the history
…dPress#65734)"

This reverts commit 6772238.
  • Loading branch information
huubl authored Oct 2, 2024
1 parent 8845f25 commit 9f5c707
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/edit-post/src/components/init-pattern-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import {
ToggleControl,
TextControl,
} from '@wordpress/components';
import { useState } from '@wordpress/element';
import { useEffect, useState } from '@wordpress/element';
import { store as editorStore } from '@wordpress/editor';

export default function InitPatternModal() {
const { editPost } = useDispatch( editorStore );
const [ isModalOpen, setIsModalOpen ] = useState( false );
const [ syncType, setSyncType ] = useState( undefined );
const [ title, setTitle ] = useState( '' );

Expand All @@ -27,9 +28,14 @@ export default function InitPatternModal() {
isNewPost: isCleanNewPost(),
};
}, [] );
const [ isModalOpen, setIsModalOpen ] = useState( () =>
isNewPost && postType === 'wp_block' ? true : false
);

useEffect( () => {
if ( isNewPost && postType === 'wp_block' ) {
setIsModalOpen( true );
}
// We only want the modal to open when the page is first loaded.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [] );

if ( postType !== 'wp_block' || ! isNewPost ) {
return null;
Expand Down

0 comments on commit 9f5c707

Please sign in to comment.