Skip to content

Commit

Permalink
fix(app): fix clicking the gear icon several times in a short period …
Browse files Browse the repository at this point in the history
…of time (#16031)

* fix(app): fix clicking the gear icon several times in a short period of time
  • Loading branch information
koji authored Aug 16, 2024
1 parent 1a42392 commit ac21cee
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions app/src/App/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react'
import { NavLink } from 'react-router-dom'
import { NavLink, useNavigate } from 'react-router-dom'
import styled from 'styled-components'
import debounce from 'lodash/debounce'

import {
ALIGN_CENTER,
Expand All @@ -14,7 +15,6 @@ import {
JUSTIFY_SPACE_BETWEEN,
JUSTIFY_SPACE_EVENLY,
Link,
SIZE_2,
SPACING,
LegacyStyledText,
TYPOGRAPHY,
Expand All @@ -29,6 +29,7 @@ import type { RouteProps } from './types'

const SALESFORCE_HELP_LINK = 'https://support.opentrons.com/s/'
const PROJECT: string = _OPENTRONS_PROJECT_
const DEBOUNCE_DURATION_MS = 300

const NavbarLink = styled(NavLink)`
color: ${COLORS.white};
Expand Down Expand Up @@ -61,7 +62,7 @@ const NavbarLink = styled(NavLink)`
background-color: ${COLORS.black90};
}
`
const NavIconLink = styled(NavLink)`
const NavIconLink = styled(Link)`
&.active > svg {
color: ${COLORS.grey30};
background-color: ${COLORS.black70};
Expand All @@ -75,8 +76,8 @@ const IconLink = styled(Link)`
`

const NavbarIcon = styled(Icon)`
width: ${SIZE_2};
height: ${SIZE_2};
width: 2rem;
height: 2rem;
padding: ${SPACING.spacing6};
border-radius: 50%;
color: ${COLORS.grey30};
Expand Down Expand Up @@ -109,9 +110,18 @@ const LogoImg = styled('img')`
`

export function Navbar({ routes }: { routes: RouteProps[] }): JSX.Element {
const navigate = useNavigate()
const navRoutes = routes.filter(
({ navLinkTo }: RouteProps) => navLinkTo != null
)

const debouncedNavigate = React.useCallback(
debounce((path: string) => {
navigate(path)
}, DEBOUNCE_DURATION_MS),
[navigate]
)

return (
<Flex
backgroundColor={COLORS.black90}
Expand Down Expand Up @@ -148,7 +158,14 @@ export function Navbar({ routes }: { routes: RouteProps[] }): JSX.Element {
alignSelf={ALIGN_STRETCH}
justifyContent={JUSTIFY_SPACE_EVENLY}
>
<NavIconLink data-testid="Navbar_settingsLink" to="/app-settings">
<NavIconLink
role="button"
data-testid="Navbar_settingsLink"
onClick={(e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault()
debouncedNavigate('/app-settings')
}}
>
<NavbarIcon name="gear" />
</NavIconLink>
<IconLink href={SALESFORCE_HELP_LINK} external>
Expand Down

0 comments on commit ac21cee

Please sign in to comment.