From 75085478aec89c4c3b2e73c2e7bfd167b6113eb6 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Thu, 19 Dec 2024 20:20:23 +0000 Subject: [PATCH] account quick switch on web --- src/components/Menu/index.web.tsx | 3 +- src/view/shell/desktop/LeftNav.tsx | 148 +++++++++++++++++++++-------- 2 files changed, 112 insertions(+), 39 deletions(-) diff --git a/src/components/Menu/index.web.tsx b/src/components/Menu/index.web.tsx index 6bbb8c21c0..d1863e478e 100644 --- a/src/components/Menu/index.web.tsx +++ b/src/components/Menu/index.web.tsx @@ -202,7 +202,7 @@ export function Outer({ ) } -export function Item({children, label, onPress, ...rest}: ItemProps) { +export function Item({children, label, onPress, style, ...rest}: ItemProps) { const t = useTheme() const {control} = useMenuContext() const { @@ -248,6 +248,7 @@ export function Item({children, label, onPress, ...rest}: ItemProps) { ? t.atoms.bg_contrast_25 : t.atoms.bg_contrast_50, ], + style, ])} {...web({ onMouseEnter, diff --git a/src/view/shell/desktop/LeftNav.tsx b/src/view/shell/desktop/LeftNav.tsx index d367e1b98e..5da5c2ce37 100644 --- a/src/view/shell/desktop/LeftNav.tsx +++ b/src/view/shell/desktop/LeftNav.tsx @@ -9,22 +9,24 @@ import { useNavigationState, } from '@react-navigation/native' +import {useAccountSwitcher} from '#/lib/hooks/useAccountSwitcher' import {usePalette} from '#/lib/hooks/usePalette' import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries' import {getCurrentRoute, isTab} from '#/lib/routes/helpers' import {makeProfileLink} from '#/lib/routes/links' import {CommonNavigatorParams} from '#/lib/routes/types' import {useGate} from '#/lib/statsig/statsig' -import {isInvalidHandle} from '#/lib/strings/handles' +import {isInvalidHandle, sanitizeHandle} from '#/lib/strings/handles' import {emitSoftReset} from '#/state/events' import {useHomeBadge} from '#/state/home-badge' import {useFetchHandle} from '#/state/queries/handle' import {useUnreadMessageCount} from '#/state/queries/messages/list-conversations' import {useUnreadNotifications} from '#/state/queries/notifications/unread' -import {useProfileQuery} from '#/state/queries/profile' -import {useSession} from '#/state/session' +import {useProfilesQuery} from '#/state/queries/profile' +import {useSession, useSessionApi} from '#/state/session' import {useComposerControls} from '#/state/shell/composer' -import {Link} from '#/view/com/util/Link' +import {useLoggedOutViewControls} from '#/state/shell/logged-out' +import {useCloseAllActiveElements} from '#/state/util' import {LoadingPlaceholder} from '#/view/com/util/LoadingPlaceholder' import {PressableWithHover} from '#/view/com/util/PressableWithHover' import {UserAvatar} from '#/view/com/util/UserAvatar' @@ -62,39 +64,119 @@ import { UserCircle_Filled_Corner0_Rounded as UserCircleFilled, UserCircle_Stroke2_Corner0_Rounded as UserCircle, } from '#/components/icons/UserCircle' +import * as Menu from '#/components/Menu' +import * as Prompt from '#/components/Prompt' import {Text} from '#/components/Typography' import {router} from '../../../routes' const NAV_ICON_WIDTH = 28 function ProfileCard() { - const {currentAccount} = useSession() - const {isLoading, data: profile} = useProfileQuery({did: currentAccount!.did}) - const {isDesktop} = useWebMediaQueries() + const {currentAccount, accounts} = useSession() + const {onPressSwitchAccount, pendingDid} = useAccountSwitcher() + const {logoutEveryAccount} = useSessionApi() + const {isLoading, data} = useProfilesQuery({ + handles: accounts.map(a => a.did), + }) + const profiles = data?.profiles + const signOutPromptControl = Prompt.usePromptControl() + const {gtTablet} = useBreakpoints() const {_} = useLingui() + const {setShowLoggedOut} = useLoggedOutViewControls() + const closeEverything = useCloseAllActiveElements() + const size = 48 - return !isLoading && profile ? ( - - - - ) : ( - - { + setShowLoggedOut(true) + closeEverything() + } + + const profile = profiles?.find(p => p.did === currentAccount!.did) + const otherAccounts = accounts + .filter(acc => acc.did !== currentAccount!.did) + .map(account => ({ + account, + profile: profiles?.find(p => p.did === account.did), + })) + + return ( + + {!isLoading && profile ? ( + + + {({props}) => ( + + )} + + + {otherAccounts && ( + <> + + {otherAccounts?.map(other => ( + + onPressSwitchAccount(other.account, 'SwitchAccount') + }> + + + {sanitizeHandle( + other.profile?.handle ?? other.account.handle, + '@', + )} + + + ))} + + + + )} + + + Add another account + + + + + Sign out + + + + + ) : ( + + )} + logoutEveryAccount('Settings')} + confirmButtonCta={_(msg`Sign out`)} + cancelButtonCta={_(msg`Cancel`)} + confirmButtonColor="negative" /> ) @@ -539,16 +621,6 @@ const styles = StyleSheet.create({ alignItems: 'center', transform: [], }, - - profileCard: { - marginVertical: 10, - width: 90, - paddingLeft: 12, - }, - profileCardTablet: { - width: 70, - }, - backBtn: { position: 'absolute', top: 12,