From 04efa8220932ac2d4538f739448d8f15238ea1be Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Thu, 13 Aug 2026 23:25:26 +0200 Subject: [PATCH] fix: retain profile popup placement --- .../components/UserRoomProfileRenderer.tsx | 2 ++ .../user-profile/UserRoomProfile.tsx | 7 ++++- src/app/hooks/useMentionClickHandler.ts | 29 +++++++++++++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/app/components/UserRoomProfileRenderer.tsx b/src/app/components/UserRoomProfileRenderer.tsx index 172eb4148..96caa8b69 100644 --- a/src/app/components/UserRoomProfileRenderer.tsx +++ b/src/app/components/UserRoomProfileRenderer.tsx @@ -42,6 +42,8 @@ function UserRoomProfileContextMenu({ state }: { state: UserRoomProfileState }) initialProfile={initialProfile} onSurfaceColorChange={setSurfaceColor} pmp={pmp} + anchor={cords} + position={position} /> diff --git a/src/app/components/user-profile/UserRoomProfile.tsx b/src/app/components/user-profile/UserRoomProfile.tsx index b7c2d7fa6..ed8f8c6be 100644 --- a/src/app/components/user-profile/UserRoomProfile.tsx +++ b/src/app/components/user-profile/UserRoomProfile.tsx @@ -1,4 +1,5 @@ import { Box, Button, color, config, Menu, MenuItem, Scroll, Text, toRem } from 'folds'; +import type { Position, RectCords } from 'folds'; import type { CSSProperties } from 'react'; import { useLayoutEffect, useMemo, useState } from 'react'; import { useNavigate } from 'react-router-dom'; @@ -416,12 +417,16 @@ type UserRoomProfileProps = { pmp?: Persona; initialProfile?: Partial; onSurfaceColorChange?: (color: string) => void; + anchor: RectCords; + position?: Position; }; export function UserRoomProfile({ userId, pmp: initialPmp, initialProfile, onSurfaceColorChange, + anchor, + position, }: Readonly) { const theme = useTheme(); const mx = useMatrixClient(); @@ -497,7 +502,7 @@ export function UserRoomProfile({ navigate(withSearchParam(getDirectCreatePath(), directSearchParam)); }; - const mentionClickHandler = useMentionClickHandler(room.roomId); + const mentionClickHandler = useMentionClickHandler(room.roomId, anchor, position); const settingsLinkBaseUrl = useSettingsLinkBaseUrl(); const linkifyOpts = useMemo( diff --git a/src/app/hooks/useMentionClickHandler.ts b/src/app/hooks/useMentionClickHandler.ts index 4191cbb58..ebf799365 100644 --- a/src/app/hooks/useMentionClickHandler.ts +++ b/src/app/hooks/useMentionClickHandler.ts @@ -1,6 +1,7 @@ import type { ReactEventHandler } from 'react'; import { useCallback } from 'react'; import { useNavigate } from 'react-router-dom'; +import type { Position, RectCords } from 'folds'; import { isRoomId, isUserId } from '$utils/matrix'; import { getHomeRoomPath, withSearchParam } from '$pages/pathUtils'; import { isSettingsSectionId } from '$features/settings/routes'; @@ -11,7 +12,11 @@ import { useMatrixClient } from './useMatrixClient'; import { useRoomNavigate } from './useRoomNavigate'; import { useSpaceOptionally } from './useSpace'; -export const useMentionClickHandler = (roomId: string): ReactEventHandler => { +export const useMentionClickHandler = ( + roomId: string, + profileAnchor?: RectCords, + profilePosition?: Position +): ReactEventHandler => { const mx = useMatrixClient(); const { navigateRoom, navigateSpace } = useRoomNavigate(); const navigate = useNavigate(); @@ -38,7 +43,14 @@ export const useMentionClickHandler = (roomId: string): ReactEventHandler