diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/view/shell/desktop/LeftNav.tsx | 52 |
1 files changed, 52 insertions, 0 deletions
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 ( <Menu.Outer> {accounts && accounts.length > 0 && ( @@ -255,6 +256,7 @@ function SwitchMenuItems({ <Menu.Divider /> </> )} + <SwitcherMenuProfileLink /> <Menu.Item label={_(msg`Add another account`)} onPress={onAddAnotherAccount}> @@ -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<HTMLAnchorElement, 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 ( + <Menu.Item + label={_(msg`Go to profile`)} + // @ts-expect-error The function signature differs on web -inb + onPress={onProfilePress} + href={profileLink}> + <Menu.ItemIcon icon={UserCircle} /> + <Menu.ItemText> + <Trans>Go to profile</Trans> + </Menu.ItemText> + </Menu.Item> + ) +} + function SwitchMenuItem({ account, profile, |