From 13b0dd174d5d3608cc0676764e3dc4659ce13153 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Sat, 9 Aug 2025 12:11:54 +0530 Subject: [PATCH] add share user button in user profile --- src/app/components/user-profile/UserChips.tsx | 84 +++++++++++++++++++ .../user-profile/UserRoomProfile.tsx | 3 +- 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/src/app/components/user-profile/UserChips.tsx b/src/app/components/user-profile/UserChips.tsx index 3c9c215a..f4b8a56a 100644 --- a/src/app/components/user-profile/UserChips.tsx +++ b/src/app/components/user-profile/UserChips.tsx @@ -36,6 +36,8 @@ import { useAllJoinedRoomsSet, useGetRoom } from '../../hooks/useGetRoom'; import { RoomAvatar, RoomIcon } from '../room-avatar'; import { getDirectRoomAvatarUrl, getRoomAvatarUrl } from '../../utils/room'; import { nameInitials } from '../../utils/common'; +import { getMatrixToUser } from '../../plugins/matrix-to'; +import { useTimeoutToggle } from '../../hooks/useTimeoutToggle'; export function ServerChip({ server }: { server: string }) { const mx = useMatrixClient(); @@ -135,6 +137,88 @@ export function ServerChip({ server }: { server: string }) { ); } +export function ShareChip({ userId }: { userId: string }) { + const [cords, setCords] = useState(); + + const [copied, setCopied] = useTimeoutToggle(); + + const open: MouseEventHandler = (evt) => { + setCords(evt.currentTarget.getBoundingClientRect()); + }; + + const close = () => setCords(undefined); + + return ( + isKeyHotkey('arrowdown', evt), + isKeyBackward: (evt: KeyboardEvent) => isKeyHotkey('arrowup', evt), + }} + > + +
+ { + copyToClipboard(userId); + setCopied(); + close(); + }} + > + Copy User ID + + { + copyToClipboard(getMatrixToUser(userId)); + setCopied(); + close(); + }} + > + Copy User Link + +
+
+ + } + > + + ) : ( + + ) + } + onClick={open} + aria-pressed={!!cords} + > + + Share + + +
+ ); +} + type MutualRoomsData = { rooms: Room[]; spaces: Room[]; diff --git a/src/app/components/user-profile/UserRoomProfile.tsx b/src/app/components/user-profile/UserRoomProfile.tsx index 7a40a622..119f76f4 100644 --- a/src/app/components/user-profile/UserRoomProfile.tsx +++ b/src/app/components/user-profile/UserRoomProfile.tsx @@ -8,7 +8,7 @@ import { useMediaAuthentication } from '../../hooks/useMediaAuthentication'; import { usePowerLevels, usePowerLevelsAPI } from '../../hooks/usePowerLevels'; import { useRoom } from '../../hooks/useRoom'; import { useUserPresence } from '../../hooks/useUserPresence'; -import { MutualRoomsChip, ServerChip } from './UserChips'; +import { MutualRoomsChip, ServerChip, ShareChip } from './UserChips'; import { AsyncStatus, useAsyncCallback } from '../../hooks/useAsyncCallback'; import { createDM } from '../../../client/action/room'; import { hasDevices } from '../../../util/matrixUtil'; @@ -105,6 +105,7 @@ export function UserRoomProfile({ userId }: UserRoomProfileProps) { )} {server && } +