From 5a074fa37acafb0cf11acbdd0a931411b1c63aa2 Mon Sep 17 00:00:00 2001 From: Inbestigator <119569726+Inbestigator@users.noreply.github.com> Date: Tue, 26 Aug 2025 08:18:40 -0700 Subject: Add profile link to switcher menu (#8867) * feat(leftnav): add profile link to switcher menu * fix: close menu on navigate --- src/view/shell/desktop/LeftNav.tsx | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/view/shell/desktop/LeftNav.tsx b/src/view/shell/desktop/LeftNav.tsx index aa18f9b70..cf1ff8425 100644 --- a/src/view/shell/desktop/LeftNav.tsx +++ b/src/view/shell/desktop/LeftNav.tsx @@ -236,6 +236,7 @@ function SwitchMenuItems({ setShowLoggedOut(true) closeEverything() } + return ( {accounts && accounts.length > 0 && ( @@ -255,6 +256,7 @@ function SwitchMenuItems({ )} + @@ -273,6 +275,56 @@ function SwitchMenuItems({ ) } +function SwitcherMenuProfileLink() { + const {_} = useLingui() + const {currentAccount} = useSession() + const navigation = useNavigation() + const context = Menu.useMenuContext() + const profileLink = currentAccount ? makeProfileLink(currentAccount) : '/' + const [pathName] = useMemo(() => router.matchPath(profileLink), [profileLink]) + const currentRouteInfo = useNavigationState(state => { + if (!state) { + return {name: 'Home'} + } + return getCurrentRoute(state) + }) + let isCurrent = + currentRouteInfo.name === 'Profile' + ? isTab(currentRouteInfo.name, pathName) && + (currentRouteInfo.params as CommonNavigatorParams['Profile']).name === + currentAccount?.handle + : isTab(currentRouteInfo.name, pathName) + const onProfilePress = useCallback( + (e: React.MouseEvent) => { + if (e.ctrlKey || e.metaKey || e.altKey) { + return + } + e.preventDefault() + context.control.close() + if (isCurrent) { + emitSoftReset() + } else { + const [screen, params] = router.matchPath(profileLink) + // @ts-expect-error TODO: type matchPath well enough that it can be plugged into navigation.navigate directly + navigation.navigate(screen, params, {pop: true}) + } + }, + [navigation, profileLink, isCurrent, context], + ) + return ( + + + + Go to profile + + + ) +} + function SwitchMenuItem({ account, profile, -- cgit 1.4.1