From cfb469ba83f9789fefbe085afa6124c6ff7f6174 Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Sun, 5 Nov 2023 23:05:07 +0900 Subject: [PATCH 1/2] Fix pattern modal reopening when making the title empty again --- .../components/start-page-options/index.js | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/packages/edit-post/src/components/start-page-options/index.js b/packages/edit-post/src/components/start-page-options/index.js index 02473fd4eaa148..880b25d9ac6bbe 100644 --- a/packages/edit-post/src/components/start-page-options/index.js +++ b/packages/edit-post/src/components/start-page-options/index.js @@ -3,7 +3,7 @@ */ import { Modal } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; -import { useState, useEffect, useMemo } from '@wordpress/element'; +import { useState, useMemo } from '@wordpress/element'; import { store as blockEditorStore, __experimentalBlockPatternsList as BlockPatternsList, @@ -62,19 +62,11 @@ function PatternSelection( { blockPatterns, onChoosePattern } ) { ); } -function StartPageOptionsModal() { - const [ modalState, setModalState ] = useState( 'initial' ); +function StartPageOptionsModal( { onClose } ) { const startPatterns = useStartPatterns(); const hasStartPattern = startPatterns.length > 0; - const shouldOpenModal = hasStartPattern && modalState === 'initial'; - - useEffect( () => { - if ( shouldOpenModal ) { - setModalState( 'open' ); - } - }, [ shouldOpenModal ] ); - if ( modalState !== 'open' ) { + if ( ! hasStartPattern ) { return null; } @@ -83,12 +75,12 @@ function StartPageOptionsModal() { className="edit-post-start-page-options__modal" title={ __( 'Choose a pattern' ) } isFullScreen - onRequestClose={ () => setModalState( 'closed' ) } + onRequestClose={ onClose } >
setModalState( 'closed' ) } + onChoosePattern={ onClose } />
@@ -96,6 +88,7 @@ function StartPageOptionsModal() { } export default function StartPageOptions() { + const [ modalState, setModalState ] = useState( 'initial' ); const shouldEnableModal = useSelect( ( select ) => { const { isCleanNewPost } = select( editorStore ); const { isEditingTemplate, isFeatureActive } = select( editPostStore ); @@ -107,9 +100,11 @@ export default function StartPageOptions() { ); }, [] ); - if ( ! shouldEnableModal ) { + if ( ! shouldEnableModal || modalState === 'closed' ) { return null; } - return ; + return ( + setModalState( 'closed' ) } /> + ); } From 8127399017676ff7ade6281b3e4446b20a4b4f9c Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Mon, 6 Nov 2023 20:48:51 +0900 Subject: [PATCH 2/2] Use boolean value --- .../edit-post/src/components/start-page-options/index.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/edit-post/src/components/start-page-options/index.js b/packages/edit-post/src/components/start-page-options/index.js index 880b25d9ac6bbe..77264d27a5e7df 100644 --- a/packages/edit-post/src/components/start-page-options/index.js +++ b/packages/edit-post/src/components/start-page-options/index.js @@ -88,7 +88,7 @@ function StartPageOptionsModal( { onClose } ) { } export default function StartPageOptions() { - const [ modalState, setModalState ] = useState( 'initial' ); + const [ isClosed, setIsClosed ] = useState( false ); const shouldEnableModal = useSelect( ( select ) => { const { isCleanNewPost } = select( editorStore ); const { isEditingTemplate, isFeatureActive } = select( editPostStore ); @@ -100,11 +100,9 @@ export default function StartPageOptions() { ); }, [] ); - if ( ! shouldEnableModal || modalState === 'closed' ) { + if ( ! shouldEnableModal || isClosed ) { return null; } - return ( - setModalState( 'closed' ) } /> - ); + return setIsClosed( true ) } />; }