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 (
-
- );
-}
-
-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,
- }}
- >
-
-
- }
- />
-
- {confirmSignOutSession && (
- }>
-
- document.body,
- clickOutsideDeactivates: true,
- onDeactivate: () => setConfirmSignOutSession(undefined),
- escapeDeactivates: stopPropagation,
- }}
- >
-
-
-
-
- )}
-
- );
-}