From 38cc08bc093e4938d3aa363f0a6e6c2e34c1ab5d Mon Sep 17 00:00:00 2001 From: Alex Benzer Date: Mon, 25 May 2026 21:40:57 -0700 Subject: [PATCH] Addressing review feedback: tidy nav-item types and shared map - Move LeftNavItem type declaration below the import block in LeftNav.tsx (it was wedged between two imports). - Extract the identical Home/Search/Messages/Notifications/MyProfile -> nav-item maps from BottomBar.tsx and Drawer.tsx into a single src/lib/routes/tab-to-nav-item.ts. --- src/lib/routes/tab-to-nav-item.ts | 17 +++++++++++++++++ src/view/shell/Drawer.tsx | 23 +++-------------------- src/view/shell/bottom-bar/BottomBar.tsx | 16 ++-------------- src/view/shell/desktop/LeftNav.tsx | 2 +- 4 files changed, 23 insertions(+), 35 deletions(-) create mode 100644 src/lib/routes/tab-to-nav-item.ts diff --git a/src/lib/routes/tab-to-nav-item.ts b/src/lib/routes/tab-to-nav-item.ts new file mode 100644 index 0000000000..f79774b5f1 --- /dev/null +++ b/src/lib/routes/tab-to-nav-item.ts @@ -0,0 +1,17 @@ +export type SharedNavTab = + | 'Home' + | 'Search' + | 'Messages' + | 'Notifications' + | 'MyProfile' + +export const TAB_TO_NAV_ITEM: Record< + SharedNavTab, + 'home' | 'search' | 'chat' | 'notifications' | 'profile' +> = { + Home: 'home', + Search: 'search', + Messages: 'chat', + Notifications: 'notifications', + MyProfile: 'profile', +} diff --git a/src/view/shell/Drawer.tsx b/src/view/shell/Drawer.tsx index 72b7bc3cf2..10e4af037f 100644 --- a/src/view/shell/Drawer.tsx +++ b/src/view/shell/Drawer.tsx @@ -10,6 +10,7 @@ import {FEEDBACK_FORM_URL, HELP_DESK_URL} from '#/lib/constants' import {type PressableScale} from '#/lib/custom-animations/PressableScale' import {useNavigationTabState} from '#/lib/hooks/useNavigationTabState' import {getTabState, TabState} from '#/lib/routes/helpers' +import {type SharedNavTab, TAB_TO_NAV_ITEM} from '#/lib/routes/tab-to-nav-item' import {type NavigationProp} from '#/lib/routes/types' import {sanitizeHandle} from '#/lib/strings/handles' import {colors} from '#/lib/styles' @@ -134,24 +135,6 @@ let DrawerProfileCard = ({ DrawerProfileCard = memo(DrawerProfileCard) export {DrawerProfileCard} -type DrawerTabOption = - | 'Home' - | 'Search' - | 'Messages' - | 'Notifications' - | 'MyProfile' - -const DRAWER_TAB_TO_NAV_ITEM: Record< - DrawerTabOption, - 'home' | 'search' | 'chat' | 'notifications' | 'profile' -> = { - Home: 'home', - Search: 'search', - Messages: 'chat', - Notifications: 'notifications', - MyProfile: 'profile', -} - let DrawerContent = ({}: React.PropsWithoutRef<{}>): React.ReactNode => { const t = useTheme() const insets = useSafeAreaInsets() @@ -173,9 +156,9 @@ let DrawerContent = ({}: React.PropsWithoutRef<{}>): React.ReactNode => { // = const onPressTab = useCallback( - (tab: DrawerTabOption, surface: 'drawer' | 'drawerHeader' = 'drawer') => { + (tab: SharedNavTab, surface: 'drawer' | 'drawerHeader' = 'drawer') => { ax.metric('nav:click', { - item: DRAWER_TAB_TO_NAV_ITEM[tab], + item: TAB_TO_NAV_ITEM[tab], surface, }) const state = navigation.getState() diff --git a/src/view/shell/bottom-bar/BottomBar.tsx b/src/view/shell/bottom-bar/BottomBar.tsx index 275af6a144..e6a1eeaad5 100644 --- a/src/view/shell/bottom-bar/BottomBar.tsx +++ b/src/view/shell/bottom-bar/BottomBar.tsx @@ -17,6 +17,7 @@ import {useMinimalShellFooterTransform} from '#/lib/hooks/useMinimalShellTransfo import {useNavigationTabState} from '#/lib/hooks/useNavigationTabState' import {clamp} from '#/lib/numbers' import {getTabState, TabState} from '#/lib/routes/helpers' +import {type SharedNavTab, TAB_TO_NAV_ITEM} from '#/lib/routes/tab-to-nav-item' import {emitSoftReset} from '#/state/events' import {useUnreadMessageCount} from '#/state/queries/messages/list-conversations' import {useUnreadNotifications} from '#/state/queries/notifications/unread' @@ -55,19 +56,6 @@ import {useActorStatus} from '#/features/liveNow' import {useDemoMode} from '#/storage/hooks/demo-mode' import {styles} from './BottomBarStyles' -type TabOptions = 'Home' | 'Search' | 'Messages' | 'Notifications' | 'MyProfile' - -const TAB_TO_NAV_ITEM: Record< - TabOptions, - 'home' | 'search' | 'chat' | 'notifications' | 'profile' -> = { - Home: 'home', - Search: 'search', - Messages: 'chat', - Notifications: 'notifications', - MyProfile: 'profile', -} - export function BottomBar({navigation}: BottomTabBarProps) { const {hasSession, currentAccount} = useSession() const t = useTheme() @@ -102,7 +90,7 @@ export function BottomBar({navigation}: BottomTabBarProps) { }, [requestSwitchToAccount, closeAllActiveElements]) const onPressTab = useCallback( - (tab: TabOptions) => { + (tab: SharedNavTab) => { ax.metric('nav:click', { item: TAB_TO_NAV_ITEM[tab], surface: 'bottomBar', diff --git a/src/view/shell/desktop/LeftNav.tsx b/src/view/shell/desktop/LeftNav.tsx index 5dbd708a1e..f19e51509f 100644 --- a/src/view/shell/desktop/LeftNav.tsx +++ b/src/view/shell/desktop/LeftNav.tsx @@ -86,6 +86,7 @@ import {useAgeAssurance} from '#/ageAssurance' import {useAnalytics} from '#/analytics' import {useActorStatus} from '#/features/liveNow' import {router} from '#/routes' +import {PlatformInfo} from '../../../../modules/expo-bluesky-swiss-army' type LeftNavItem = | 'home' @@ -97,7 +98,6 @@ type LeftNavItem = | 'saved' | 'profile' | 'settings' -import {PlatformInfo} from '../../../../modules/expo-bluesky-swiss-army' const LARGE_ELEMENT_SIZE = 48 const NAV_ICON_WIDTH = 28