import React from 'react'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; import { Avatar, Box, Icon, Icons, Text, color, config, toRem } from 'folds'; import { NavButton, NavItem, NavItemContent } from '../../../components/nav'; import { UserAvatar } from '../../../components/user-avatar'; import { useMatrixClient } from '../../../hooks/useMatrixClient'; import { useUserProfile } from '../../../hooks/useUserProfile'; import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication'; import { getMxIdLocalPart, mxcUrlToHttp } from '../../../utils/matrix'; import { nameInitials } from '../../../utils/common'; import { ScreenSize, useScreenSizeContext } from '../../../hooks/useScreenSize'; import { useOpenSettingsSheet } from '../../../state/hooks/settingsSheet'; import { SETTINGS_SHEET_DRAG_ORIGIN_ATTR } from '../../../features/settings/MobileSettingsHorseshoe'; import { SETTINGS_FROM_IN_APP_STATE } from '../../../features/settings/SettingsScreen'; import { getSettingsPath } from '../../pathUtils'; const MONO_FONT = '"JetBrains Mono Variable", ui-monospace, monospace'; const ROW_MIN_HEIGHT = toRem(68); export function DirectSelfRow() { const { t } = useTranslation(); const mx = useMatrixClient(); const useAuthentication = useMediaAuthentication(); const navigate = useNavigate(); const screenSize = useScreenSizeContext(); const openSheet = useOpenSettingsSheet(); const userId = mx.getSafeUserId(); const profile = useUserProfile(userId); // Mobile: open the atom-driven bottom-up sheet so the DM list stays // visible above with a void gap (the )|( horseshoe). The // MobileSettingsHorseshoe wrapper owns the drag/animation; the tap // just commits to fully-open. // // Desktop: navigate to `/settings` — the route renders Settings in // the right pane of the nested horseshoe (DM list still on the left). const handleOpen = () => { if (screenSize === ScreenSize.Mobile) { openSheet(); } else { navigate(getSettingsPath(), { state: SETTINGS_FROM_IN_APP_STATE }); } }; const displayName = profile.displayName ?? getMxIdLocalPart(userId) ?? userId; const avatarUrl = profile.avatarUrl ? mxcUrlToHttp(mx, profile.avatarUrl, useAuthentication, 96, 96, 'crop') ?? undefined : undefined; // `data-settings-drag-origin` is the marker the mobile horseshoe // wrapper uses to detect drag-up gestures starting on this row. // Document-level touch/pointer listeners in `MobileSettingsHorseshoe` // check `target.closest('[data-settings-drag-origin]')` so any // touch landing inside this Box (anywhere on the row) starts the // open-drag while still leaving the row's own onClick handler // free to fire when there's no movement (tap → openSheet). return ( ( {nameInitials(displayName)} )} /> {t('Direct.self_row_label')} {userId} {t('Direct.self_row_preview')} ); }