Bluesky app fork with some witchin' additions 💫

Add profile link to switcher menu (#8867)

* feat(leftnav): add profile link to switcher menu

* fix: close menu on navigate

authored by

Inbestigator and committed by
GitHub
5a074fa3 df20ae23

+52
+52
src/view/shell/desktop/LeftNav.tsx
··· 236 236 setShowLoggedOut(true) 237 237 closeEverything() 238 238 } 239 + 239 240 return ( 240 241 <Menu.Outer> 241 242 {accounts && accounts.length > 0 && ( ··· 255 256 <Menu.Divider /> 256 257 </> 257 258 )} 259 + <SwitcherMenuProfileLink /> 258 260 <Menu.Item 259 261 label={_(msg`Add another account`)} 260 262 onPress={onAddAnotherAccount}> ··· 270 272 </Menu.ItemText> 271 273 </Menu.Item> 272 274 </Menu.Outer> 275 + ) 276 + } 277 + 278 + function SwitcherMenuProfileLink() { 279 + const {_} = useLingui() 280 + const {currentAccount} = useSession() 281 + const navigation = useNavigation() 282 + const context = Menu.useMenuContext() 283 + const profileLink = currentAccount ? makeProfileLink(currentAccount) : '/' 284 + const [pathName] = useMemo(() => router.matchPath(profileLink), [profileLink]) 285 + const currentRouteInfo = useNavigationState(state => { 286 + if (!state) { 287 + return {name: 'Home'} 288 + } 289 + return getCurrentRoute(state) 290 + }) 291 + let isCurrent = 292 + currentRouteInfo.name === 'Profile' 293 + ? isTab(currentRouteInfo.name, pathName) && 294 + (currentRouteInfo.params as CommonNavigatorParams['Profile']).name === 295 + currentAccount?.handle 296 + : isTab(currentRouteInfo.name, pathName) 297 + const onProfilePress = useCallback( 298 + (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => { 299 + if (e.ctrlKey || e.metaKey || e.altKey) { 300 + return 301 + } 302 + e.preventDefault() 303 + context.control.close() 304 + if (isCurrent) { 305 + emitSoftReset() 306 + } else { 307 + const [screen, params] = router.matchPath(profileLink) 308 + // @ts-expect-error TODO: type matchPath well enough that it can be plugged into navigation.navigate directly 309 + navigation.navigate(screen, params, {pop: true}) 310 + } 311 + }, 312 + [navigation, profileLink, isCurrent, context], 313 + ) 314 + return ( 315 + <Menu.Item 316 + label={_(msg`Go to profile`)} 317 + // @ts-expect-error The function signature differs on web -inb 318 + onPress={onProfilePress} 319 + href={profileLink}> 320 + <Menu.ItemIcon icon={UserCircle} /> 321 + <Menu.ItemText> 322 + <Trans>Go to profile</Trans> 323 + </Menu.ItemText> 324 + </Menu.Item> 273 325 ) 274 326 } 275 327