Skip to content

Commit cd5e5fe

Browse files
committed
refactor: add useVisibleAppLinks hook
1 parent 4e324aa commit cd5e5fe

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed
Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
1-
import { recordEntries } from '@curvefi/prices-api/objects.util'
21
import Box from '@mui/material/Box'
32
import Button from '@mui/material/Button'
4-
import { useAnalyticsApp } from '@ui-kit/hooks/useFeatureFlags'
5-
import { APP_LINK, type AppMenuOption, getInternalUrl } from '@ui-kit/shared/routes'
3+
import { type AppMenuOption, getInternalUrl } from '@ui-kit/shared/routes'
64
import { RouterLink } from '@ui-kit/shared/ui/RouterLink'
5+
import { useVisibleAppLinks } from './useVisibleAppLinks'
76

87
type AppNavAppsProps = { currentMenu: AppMenuOption; onChange: (appName: AppMenuOption) => void; networkId: string }
98

10-
export const AppButtonLinks = ({ currentMenu, onChange, networkId }: AppNavAppsProps) => {
11-
const showAnalytics = useAnalyticsApp()
12-
const apps = recordEntries(APP_LINK).filter(([app]) => app !== 'analytics' || showAnalytics)
13-
14-
return (
15-
<Box display="flex" alignItems="center" marginX={[2, 3, 4]} gap={2}>
16-
{apps.map(([menu, { label, routes }]) => (
17-
<Button
18-
key={menu}
19-
color="navigation"
20-
size="small"
21-
className={currentMenu === menu ? 'current' : ''}
22-
component={RouterLink}
23-
onClick={() => onChange(menu as AppMenuOption)}
24-
href={getInternalUrl(routes[0].app, networkId)}
25-
data-testid={`app-link-${menu}`}
26-
>
27-
{label}
28-
</Button>
29-
))}
30-
</Box>
31-
)
32-
}
9+
export const AppButtonLinks = ({ currentMenu, onChange, networkId }: AppNavAppsProps) => (
10+
<Box display="flex" alignItems="center" marginX={[2, 3, 4]} gap={2}>
11+
{useVisibleAppLinks().map(([menu, { label, routes }]) => (
12+
<Button
13+
key={menu}
14+
color="navigation"
15+
size="small"
16+
className={currentMenu === menu ? 'current' : ''}
17+
component={RouterLink}
18+
onClick={() => onChange(menu as AppMenuOption)}
19+
href={getInternalUrl(routes[0].app, networkId)}
20+
data-testid={`app-link-${menu}`}
21+
>
22+
{label}
23+
</Button>
24+
))}
25+
</Box>
26+
)

packages/curve-ui-kit/src/widgets/Header/MobileHeader.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { SidebarSection } from './SidebarSection'
1616
import { SocialSidebarSection } from './SocialSidebarSection'
1717
import { HeaderImplementationProps } from './types'
1818
import { useMainNavRef } from './useMainNavRef'
19+
import { useVisibleAppLinks } from './useVisibleAppLinks'
1920

2021
const HIDE_SCROLLBAR = {
2122
// hide the scrollbar, on mobile it's not needed, and it messes up with the SideBarFooter
@@ -41,19 +42,20 @@ export const MobileHeader = ({
4142
const toggleSidebar = useCallback(() => setSidebarOpen((isOpen) => !isOpen), [])
4243
const pathname = usePathname()
4344
const top = useLayoutStore((state) => state.navHeight)
45+
const appLinks = useVisibleAppLinks()
4446

4547
useEffect(() => () => closeSidebar(), [pathname, closeSidebar]) // close when URL changes due to clicking a link
4648

4749
const otherAppSections = useMemo(
4850
() =>
49-
Object.entries(APP_LINK)
51+
appLinks
5052
.filter(([appName]) => appName != currentMenu)
5153
.map(([appName, { label, routes }]) => ({
5254
appName,
5355
title: label,
5456
pages: routes.map((p) => routeToPage(p, { networkId, pathname })),
5557
})),
56-
[currentMenu, networkId, pathname],
58+
[appLinks, currentMenu, networkId, pathname],
5759
)
5860
return (
5961
<AppBar

0 commit comments

Comments
 (0)