From 8fc750447a755d72dcde41823d92a99692050dee Mon Sep 17 00:00:00 2001 From: niki <295591807+nikiwastaken@users.noreply.github.com> Date: Sat, 27 Jun 2026 19:20:10 +0000 Subject: [PATCH] Remove account switcher tab --- src/app/components/user-profile/UserHero.tsx | 2 +- .../client/sidebar/AccountSwitcherTab.tsx | 423 ------------------ 2 files changed, 1 insertion(+), 424 deletions(-) delete mode 100644 src/app/pages/client/sidebar/AccountSwitcherTab.tsx diff --git a/src/app/components/user-profile/UserHero.tsx b/src/app/components/user-profile/UserHero.tsx index d55f1ef62..da6f57fab 100644 --- a/src/app/components/user-profile/UserHero.tsx +++ b/src/app/components/user-profile/UserHero.tsx @@ -238,7 +238,7 @@ export function UserHero({ WebkitBoxOrient: 'vertical', overflow: 'hidden', fontStyle: allowEditing && !status ? 'italic' : 'normal', - opacity: allowEditing && !status ? config.opacity.Placeholder : 1 + opacity: allowEditing && !status ? config.opacity.Placeholder : 1, }} > {status || (allowEditing && "What's on your mind?")} diff --git a/src/app/pages/client/sidebar/AccountSwitcherTab.tsx b/src/app/pages/client/sidebar/AccountSwitcherTab.tsx deleted file mode 100644 index bb1ff8b29..000000000 --- a/src/app/pages/client/sidebar/AccountSwitcherTab.tsx +++ /dev/null @@ -1,423 +0,0 @@ -import type { MouseEvent, MouseEventHandler } from 'react'; -import { useCallback, useState } from 'react'; -import type { RectCords } from 'folds'; -import { - Box, - Button, - Dialog, - Header, - Menu, - MenuItem, - PopOut, - Text, - config, - toRem, - Chip, - Spinner, - Overlay, - OverlayBackdrop, - OverlayCenter, - Line, -} from 'folds'; -import FocusTrap from 'focus-trap-react'; -import { useAtom, useAtomValue, useSetAtom } from 'jotai'; -import { useNavigate } from 'react-router-dom'; -import type { Session } from '$state/sessions'; -import { sessionsAtom, activeSessionIdAtom, backgroundUnreadCountsAtom } from '$state/sessions'; -import { - SidebarItemTooltip, - SidebarAvatar, - SidebarUnreadBadge, - SidebarItem, -} from '$components/sidebar'; -import { UserAvatar } from '$components/user-avatar'; -import { nameInitials } from '$utils/common'; -import { getMxIdLocalPart, mxcUrlToHttp } from '$utils/matrix'; -import { stopPropagation } from '$utils/keyboard'; -import { getHomePath, getLoginPath, withSearchParam } from '$pages/pathUtils'; -import { logoutClient, initClient, stopClient } from '$client/initMatrix'; -import { useMatrixClient } from '$hooks/useMatrixClient'; -import { useUserProfile } from '$hooks/useUserProfile'; -import { useMediaAuthentication } from '$hooks/useMediaAuthentication'; -import { useSessionProfiles } from '$hooks/useSessionProfiles'; -import { useOpenSettings } from '$features/settings'; -import { createLogger } from '$utils/debug'; -import { useClientConfig } from '$hooks/useClientConfig'; -import { UnreadBadge, UnreadBadgeCenter } from '$components/unread-badge'; -import { Check, chipIcon, GearSix, menuIcon, Plus } from '$components/icons/phosphor'; -import { useSetting } from '$state/hooks/settings'; -import { settingsAtom } from '$state/settings'; -import { usePathWithOrigin } from '$hooks/usePathWithOrigin'; - -const log = createLogger('AccountSwitcherTab'); - -function AccountRow({ - session, - isActive, - displayName, - avatarUrl, - isBusy, - unread, - onSwitch, - onSignOut, -}: { - session: Session; - isActive: boolean; - displayName?: string; - avatarUrl?: string; - isBusy?: boolean; - unread?: { total: number; highlight: number }; - onSwitch: (session: Session) => void; - onSignOut: (session: Session) => void; -}) { - const localPart = getMxIdLocalPart(session.userId) ?? session.userId; - const server = session.userId.split(':')[1] ?? session.baseUrl; - const label = displayName ?? localPart; - - return ( - - {nameInitials(label)}} - /> - - } - after={ - - {!isActive && unread && unread.total > 0 && ( - - 0} count={unread.total} /> - - )} - {isActive && chipIcon(Check, { style: { color: 'var(--mx-c-success)' } })} - {isBusy ? ( - - ) : ( - { - e.stopPropagation(); - onSignOut(session); - }} - > - Sign out - - )} - - } - onClick={() => !isActive && !isBusy && onSwitch(session)} - > - - - {label} - - - {isActive ? session.userId : server} - - - - ); -} - -export function AccountSwitcherTab({ isBottom }: { isBottom?: boolean }) { - const mx = useMatrixClient(); - const navigate = useNavigate(); - const sessions = useAtomValue(sessionsAtom); - const [activeSessionId, setActiveSessionId] = useAtom(activeSessionIdAtom); - const setSessions = useSetAtom(sessionsAtom); - const useAuthentication = useMediaAuthentication(); - const backgroundUnreads = useAtomValue(backgroundUnreadCountsAtom); - const setBackgroundUnreads = useSetAtom(backgroundUnreadCountsAtom); - const openSettings = useOpenSettings(); - const [oldSidebar] = useSetting(settingsAtom, 'oldSidebar'); - - // Total unread count across all background sessions (for the sidebar badge). - const totalBackgroundUnread = Object.entries(backgroundUnreads) - .filter(([uid]) => uid !== (activeSessionId ?? sessions[0]?.userId)) - .reduce((acc, [, u]) => acc + u.total, 0); - const totalBackgroundHighlight = Object.entries(backgroundUnreads) - .filter(([uid]) => uid !== (activeSessionId ?? sessions[0]?.userId)) - .reduce((acc, [, u]) => acc + u.highlight, 0); - const anyBackgroundHighlight = totalBackgroundHighlight > 0; - - const [menuAnchor, setMenuAnchor] = useState(); - const [busyUserIds, setBusyUserIds] = useState(new Set()); - const [confirmSignOutSession, setConfirmSignOutSession] = useState( - undefined - ); - - const activeSession = sessions.find((s) => s.userId === activeSessionId) ?? sessions[0]; - - const myUserId = mx.getUserId() ?? ''; - const activeProfile = useUserProfile(myUserId); - const activeAvatarUrl = activeProfile.avatarUrl - ? (mxcUrlToHttp(mx, activeProfile.avatarUrl, useAuthentication, 96, 96, 'crop') ?? undefined) - : undefined; - const activeDisplayName = activeProfile.displayName; - - const sessionProfiles = useSessionProfiles(sessions); - - const { disableAccountSwitcher } = useClientConfig(); - - const loginUrl = usePathWithOrigin(getLoginPath()); - - const handleToggle: MouseEventHandler = (evt) => { - if (disableAccountSwitcher) { - openSettings(); - return; - } - const cords = evt.currentTarget.getBoundingClientRect(); - setMenuAnchor((cur) => (cur ? undefined : cords)); - }; - - const handleSwitch = useCallback( - (session: Session) => { - log.log('switching to account', session.userId); - setMenuAnchor(undefined); - navigate(getHomePath(), { replace: true }); - setActiveSessionId(session.userId); - // Clear the unread badge for the account we're now switching into. - setBackgroundUnreads((prev) => { - const next = { ...prev }; - delete next[session.userId]; - return next; - }); - }, - [navigate, setActiveSessionId, setBackgroundUnreads] - ); - - const handleSignOut = useCallback( - async (session: Session) => { - log.log('signing out', session.userId); - setMenuAnchor(undefined); - setBusyUserIds((prev) => new Set(prev).add(session.userId)); - try { - if (session.userId === mx.getUserId()) { - await logoutClient(mx, session); - setSessions({ type: 'DELETE', session }); - setActiveSessionId( - sessions.find((s) => s.userId !== session.userId)?.userId ?? undefined - ); - window.location.reload(); - } else { - try { - const tempMx = await initClient(session); - await logoutClient(tempMx, session); - } catch (err) { - log.error('failed to logout background session, IndexedDB may remain', err); - } - setSessions({ type: 'DELETE', session }); - if (activeSessionId === session.userId) { - setActiveSessionId( - sessions.find((s) => s.userId !== session.userId)?.userId ?? undefined - ); - } - } - } catch (err) { - log.error('Logout failed', err); - } finally { - setBusyUserIds((prev) => { - const next = new Set(prev); - next.delete(session.userId); - return next; - }); - } - }, - [mx, sessions, activeSessionId, setSessions, setActiveSessionId] - ); - - const handleAddAccount = () => { - const url = withSearchParam(loginUrl, { addAccount: '1' }); - setMenuAnchor(undefined); - stopClient(mx); - setTimeout(() => window.location.assign(url), 100); - }; - - const handleOpenSettings = () => { - setMenuAnchor(undefined); - openSettings(); - }; - - const activeLocalPart = - getMxIdLocalPart(activeSession?.userId ?? '') ?? activeSession?.userId ?? ''; - const label = activeDisplayName ?? activeLocalPart; - - if (!activeSession) return null; - - return ( - - - {(triggerRef) => ( - 1} - > - {nameInitials(label)}} - /> - - )} - - {(totalBackgroundUnread > 0 || anyBackgroundHighlight) && ( - - )} - - setMenuAnchor(undefined), - clickOutsideDeactivates: true, - isKeyForward: (evt: KeyboardEvent) => evt.key === 'ArrowDown', - isKeyBackward: (evt: KeyboardEvent) => evt.key === 'ArrowUp', - escapeDeactivates: stopPropagation, - }} - > - - - - Accounts - - {sessions.map((session) => { - const isActive = session.userId === (activeSessionId ?? sessions[0]?.userId); - let rowDisplayName: string | undefined; - let rowAvatarUrl: string | undefined; - if (isActive) { - rowDisplayName = activeDisplayName; - rowAvatarUrl = activeAvatarUrl; - } else { - const prof = sessionProfiles[session.userId]; - rowDisplayName = prof?.displayName; - rowAvatarUrl = prof?.avatarHttpUrl; - } - return ( - { - setMenuAnchor(undefined); - setConfirmSignOutSession(pendingSession); - }} - /> - ); - })} - - Add Account - - {/*This will defo need to be reverted w the new statuses, w the right changes in the SidebarNav to make the cog a permanent fixture but democracy wants old style*/} - {oldSidebar && ( - <> - - - Settings - - - )} - - - - } - /> - - {confirmSignOutSession && ( - }> - - document.body, - clickOutsideDeactivates: true, - onDeactivate: () => setConfirmSignOutSession(undefined), - escapeDeactivates: stopPropagation, - }} - > - -
- - Sign out - -
- - - Are you sure you want to sign out of {confirmSignOutSession.userId}? - - - - - - -
-
-
-
- )} -
- ); -}