Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace FullscreenMode from Class components to functional components. #32925

Merged
merged 6 commits into from
Jun 25, 2021

Conversation

chiilog
Copy link
Contributor

@chiilog chiilog commented Jun 23, 2021

Related #22890

Replace FullscreenMode from Class components to functional components.

I changed test code because useEffect does not seem to be executed when the component is rendered with shallow.

How has this been tested?

  1. npm run test-unit

and

  1. Click "options" icon in editor.
  2. Click "Fullscreen mode".

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jun 23, 2021
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @chiilog! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

return null;
}
}
}, [ isActive ] );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are some issues with the logic here, I see:

  • isSticky is not a state in the previous implementation and changing its value shouldn't cause an effect to run, basically it needs to be stored in a ref ( useRef )
  • We can probably combine the effects that have isActive as a dependency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@youknowriad Thank you for the review. I modified useStatus to useRef.

useEffect( () => {
return () => {
if ( isSticky ) {
if ( isSticky.current ) {
document.body.classList.add( 'sticky-menu' );
}
};
}, [ isSticky ] );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the dependency sound useless

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@youknowriad Oops! I overlooked the specification of useRef. I fixed it again.

// `is-fullscreen-mode` is set in PHP as a body class by Gutenberg, and this causes
// `sticky-menu` to be applied by WordPress and prevents the admin menu being scrolled
// even if `is-fullscreen-mode` is then removed. Let's remove `sticky-menu` here as
// a consequence of the FullscreenMode setup
if ( document.body.classList.contains( 'sticky-menu' ) ) {
this.isSticky = true;
isSticky.current = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, so if I'm reading properly, isSticky is only used inside that effect, it means it can be just a local variable right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I think too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind making that change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I've integrated a useEffect that does cleanup, so isSticky no longer needs a useRef and can be defined in a let.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks for the PR

@youknowriad youknowriad merged commit 3ab9498 into WordPress:trunk Jun 25, 2021
@github-actions github-actions bot added this to the Gutenberg 11.0 milestone Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants