e2corporation commented on code in PR #3107:
URL: https://github.com/apache/incubator-devlake/pull/3107#discussion_r980359346
##########
config-ui/src/components/Nav.jsx:
##########
@@ -15,73 +15,104 @@
* limitations under the License.
*
*/
-import React from 'react'
+import React, { useContext, useEffect, useState, useCallback } from 'react'
import { Alignment, Position, Popover, Navbar, Icon } from '@blueprintjs/core'
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) => {
+ uiContext.changeSidebarVisibility(open)
+ setMenuClass((_) =>
+ open ? 'navbarMenuButtonSidebarOpened' : 'navbarMenuButton'
+ )
+ }
+
+ useEffect(
+ () =>
+ uiContext.desktopBreakpointWidth <= size.width
+ ? !uiContext.sidebarVisible && toggleSidebarOpen(true)
+ : toggleSidebarOpen(false),
+ [size]
+ )
+
return (
<Navbar className='navbar'>
- <Navbar.Group align={Alignment.RIGHT}>
- <a
- href='https://github.com/apache/incubator-devlake'
- rel='noreferrer'
- target='_blank'
- className='navIconLink'
- >
- <Icon icon='git-branch' size={16} />
- </a>
- <Navbar.Divider />
- <a
- href='mailto:[email protected]'
- rel='noreferrer'
- target='_blank'
- className='navIconLink'
- >
- <Icon icon='envelope' size={16} />
- </a>
- <Navbar.Divider />
- {/* DISCORD: !DISABLED! */}
- {/* <a href='https://discord.com/invite/83rDG6ydVZ' rel='noreferrer'
target='_blank' className='navIconLink'>
+ <Navbar.Group className={menuClass}>
+ <Icon
+ icon={uiContext.sidebarVisible ? 'menu-closed' : 'menu-open'}
+ onClick={toggleSidebarOpen.bind(null, !uiContext.sidebarVisible)}
Review Comment:
In order to resolve one of the ESLint Errors, this can be refactored to:
```suggestion
onClick={(e) => toggleSidebarOpen(!uiContext.sidebarVisible)}
```
##########
config-ui/src/components/Nav.jsx:
##########
@@ -15,73 +15,104 @@
* limitations under the License.
*
*/
-import React from 'react'
+import React, { useContext, useEffect, useState, useCallback } from 'react'
import { Alignment, Position, Popover, Navbar, Icon } from '@blueprintjs/core'
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) => {
+ uiContext.changeSidebarVisibility(open)
+ setMenuClass((_) =>
+ open ? 'navbarMenuButtonSidebarOpened' : 'navbarMenuButton'
+ )
+ }
+
+ useEffect(
+ () =>
+ uiContext.desktopBreakpointWidth <= size.width
+ ? !uiContext.sidebarVisible && toggleSidebarOpen(true)
+ : toggleSidebarOpen(false),
+ [size]
+ )
+
return (
<Navbar className='navbar'>
- <Navbar.Group align={Alignment.RIGHT}>
- <a
- href='https://github.com/apache/incubator-devlake'
- rel='noreferrer'
- target='_blank'
- className='navIconLink'
- >
- <Icon icon='git-branch' size={16} />
- </a>
- <Navbar.Divider />
- <a
- href='mailto:[email protected]'
- rel='noreferrer'
- target='_blank'
- className='navIconLink'
- >
- <Icon icon='envelope' size={16} />
- </a>
- <Navbar.Divider />
- {/* DISCORD: !DISABLED! */}
- {/* <a href='https://discord.com/invite/83rDG6ydVZ' rel='noreferrer'
target='_blank' className='navIconLink'>
+ <Navbar.Group className={menuClass}>
+ <Icon
+ icon={uiContext.sidebarVisible ? 'menu-closed' : 'menu-open'}
+ onClick={toggleSidebarOpen.bind(null, !uiContext.sidebarVisible)}
Review Comment:
@henit-chobisa In order to resolve one of the ESLint Errors, this can be
refactored to:
```suggestion
onClick={(e) => toggleSidebarOpen(!uiContext.sidebarVisible)}
```
--
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]