From 5e2680206c7511e6165a424c82d36c1ba5e98ce0 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Mon, 6 Jan 2025 23:41:48 +0000 Subject: [PATCH] move menu components out to separate component --- src/view/shell/desktop/LeftNav.tsx | 159 ++++++++++++++++------------- 1 file changed, 89 insertions(+), 70 deletions(-) diff --git a/src/view/shell/desktop/LeftNav.tsx b/src/view/shell/desktop/LeftNav.tsx index b0e58b156d..12f19f68a2 100644 --- a/src/view/shell/desktop/LeftNav.tsx +++ b/src/view/shell/desktop/LeftNav.tsx @@ -1,5 +1,6 @@ import React from 'react' import {StyleSheet, View} from 'react-native' +import {AppBskyActorDefs} from '@atproto/api' import {FontAwesomeIconStyle} from '@fortawesome/react-native-fontawesome' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' @@ -23,7 +24,7 @@ import {useFetchHandle} from '#/state/queries/handle' import {useUnreadMessageCount} from '#/state/queries/messages/list-conversations' import {useUnreadNotifications} from '#/state/queries/notifications/unread' import {useProfilesQuery} from '#/state/queries/profile' -import {useSession, useSessionApi} from '#/state/session' +import {SessionAccount, useSession, useSessionApi} from '#/state/session' import {useComposerControls} from '#/state/shell/composer' import {useLoggedOutViewControls} from '#/state/shell/logged-out' import {useCloseAllActiveElements} from '#/state/util' @@ -33,6 +34,7 @@ import {UserAvatar} from '#/view/com/util/UserAvatar' import {NavSignupCard} from '#/view/shell/NavSignupCard' import {atoms as a, tokens, useBreakpoints, useTheme} from '#/alf' import {Button, ButtonIcon, ButtonText} from '#/components/Button' +import {DialogControlProps} from '#/components/Dialog' import {ArrowBoxLeft_Stroke2_Corner0_Rounded as LeaveIcon} from '#/components/icons/ArrowBoxLeft' import { Bell_Filled_Corner0_Rounded as BellFilled, @@ -77,7 +79,6 @@ const NAV_ICON_WIDTH = 28 function ProfileCard() { const {currentAccount, accounts} = useSession() - const {onPressSwitchAccount, pendingDid} = useAccountSwitcher() const {logoutEveryAccount} = useSessionApi() const {isLoading, data} = useProfilesQuery({ handles: accounts.map(acc => acc.did), @@ -86,17 +87,10 @@ function ProfileCard() { const signOutPromptControl = Prompt.usePromptControl() const {gtTablet} = useBreakpoints() const {_} = useLingui() - const {setShowLoggedOut} = useLoggedOutViewControls() - const closeEverything = useCloseAllActiveElements() const t = useTheme() const size = 48 - const onAddAnotherAccount = () => { - setShowLoggedOut(true) - closeEverything() - } - const profile = profiles?.find(p => p.did === currentAccount!.did) const otherAccounts = accounts .filter(acc => acc.did !== currentAccount!.did) @@ -162,67 +156,10 @@ function ProfileCard() { ) }} - - {otherAccounts && otherAccounts.length > 0 && ( - <> - - - Switch account - - {otherAccounts?.map(other => ( - - onPressSwitchAccount(other.account, 'SwitchAccount') - }> - - - - - {sanitizeHandle( - other.profile?.handle ?? other.account.handle, - '@', - )} - - - ))} - - - - )} - - - - Add another account - - - - - - Sign out - - - + ) : ( { + setShowLoggedOut(true) + closeEverything() + } + return ( + + {accounts && accounts.length > 0 && ( + <> + + + Switch account + + {accounts.map(other => ( + + onPressSwitchAccount(other.account, 'SwitchAccount') + }> + + + + + {sanitizeHandle( + other.profile?.handle ?? other.account.handle, + '@', + )} + + + ))} + + + + )} + + + + Add another account + + + + + + Sign out + + + + ) +} + interface NavItemProps { count?: string hasNew?: boolean