Edit Post: Fix pattern modal reopening when making the title empty again#55873
Merged
Conversation
|
Size Change: +845 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
jsnajdr
approved these changes
Nov 6, 2023
| } | ||
|
|
||
| export default function StartPageOptions() { | ||
| const [ modalState, setModalState ] = useState( 'initial' ); |
Member
There was a problem hiding this comment.
It's nice that you've been able to reduce the three-state (initial, open, closed) logic into just two states, "open", "closed". The code could be further simplified to use a single boolean value:
const [ isClosed, setClosed ] = useState( false );
Contributor
|
The code matches very closely what I also did in another PR, so that's very reassuring #55117 (comment) 😄 Great to get this merged first, thanks! 👍 |
Member
|
Apologies @talldan for causing merge conflicts in your PR 🙂 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #55847
What?
This PR fixes an issue where after closing the pattern modal when opening a new page, if you make the post title empty again, the modal appears again.
79a073c74186e99fd84a7b8f48a6b898.mp4
Why?
This modal primarily consists of
StartPageOptionsand a childStartPageOptionsModalcomponent. Whether this modal is opened is managed by the childStartPageOptionsModalcomponent.Whether or not child
StartPageOptionsModalcomponents are rendered is controlled by theshouldOpenModalvariable. This variable contains the condition whether the post is empty or not (isCleanNewPost).When you enter a post title and then empty the title, the
shouldOpenModalvariable changes fromfalsetotrue, causing theStartPageOptionsModalcomponent to be rendered again.As a result, the
StartPageOptionsModalcomponent'smodalStateis initialized and the modal is displayed again.How?
I decided to manage whether the modal is closed or not using a higher-level component, the
StartPageOptionscomponent. This PR is related to #53673 which improved performance, but should not impact performance.Testing Instructions