LF-5232 Fix farm notes modal not closing when clicking my profile icon or feedback button#4118
Conversation
…kSurvey, TopMenu)
… to outside-initiated close events
This was originally created to handle a click-away listener bug on TopMenu when setActiveDrawer(null) was used with it. However, I wanted to extend to all components to decrease some of the boilerplate with the repeated activeName === drawerName etc.
| * because it verifies it is still the active drawer before applying `null`. | ||
| */ | ||
| const closeDrawer = () => { | ||
| setActiveDrawer((prev) => (prev === drawerName ? null : prev)); |
There was a problem hiding this comment.
The useDrawerState hook was actually created specifically to make it easier for components to use this functional setter in closeDrawer(). The original implementation which just had
setActiveDrawer(null)on each close, produced a bug specific to the TopMenu Profile Menu, where clicking on a new drawer initiator (e.g. FeedbackForm) would trigger setActiveDrawer('feedbackForm') AND THEN also trigger the click-away listener on TopMenu, triggering its onClose() and thus setActiveDrawer(null). The result was that the feedback form would not open until you clicked again.
Right now only the TopMenu is set up with a click-away listener such that this style of onClose() is necessary, but I figured putting it here would make it safer to consume this pattern in the future, in case other participants did have click away listeners set up eventually.
And then as a bonus this hook API rather cleaned up the component logic as well!
0dd1292 to
12fac9f
Compare
Description
This PR centralizes the visibility state for all the right side-drawers and the TopMenu Profile Menu into a single global value
activeDrawer, so that a most a single drawer (or menu) can be opened at a time.Each individual's drawer (or menu)'s open state is then derived from the global
activeDrawer:The existing
AppUIContext(which previously trackedisFeedbackFormOpen,setIsFeedBackFormOpen), was already perfect for holding this state, and a common exported hook (useDrawerState) can now replace localized[isOpen, setIsOpen]style state in each component.Extending the pattern to future drawers
Now to create a new drawer that participates in this mutually exclusive application state, register the name in the
appContext.tstype:and interact with it like this in the component, destructuring only the needed values
Jira link: https://lite-farm.atlassian.net/browse/LF-5232
Type of change
How Has This Been Tested?
Checklist:
pnpm i18nto help with this)