e2corporation commented on code in PR #3107:
URL: https://github.com/apache/incubator-devlake/pull/3107#discussion_r975648117
##########
config-ui/src/components/Nav.jsx:
##########
@@ -26,11 +26,41 @@ import {
import '@/styles/nav.scss'
import { ReactComponent as SlackIcon } from
'@/images/slack-mark-monochrome-black.svg'
import { ReactComponent as SlackLogo } from '@/images/slack-rgb.svg'
+import UIContext from '../store/UIContext'
+import useWindowSize from '../hooks/useWIndowSize'
+
const Nav = () => {
+ const uiContext = useContext(UIContext);
+ const [menuClass, setMenuClass] = useState("navbarMenuButton");
+ const size = useWindowSize();
+
+ const toggleSidebarOpen = (open) => {
Review Comment:
I think this could be refactored to be more declarative and drop the need
for using the `IF` and `return` statements.
```suggestion
const toggleSidebarOpen = (open) => {
uiContext.changeSidebarVisibility(open)
setMenuClass(open ? 'navbarMenuButtonSidebarOpened' : 'navbarMenuButton'
}
```
If the initial state is always guaranteed to be `navbarMenuButton` as the
fallback, you could also use the callback mode of the state setter and rewrite
the above statement like this.
```suggestion
const toggleSidebarOpen = (open) => {
uiContext.changeSidebarVisibility(open)
setMenuClass((currentMenuClass) => open ?
'navbarMenuButtonSidebarOpened' : currentMenuClass
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]