add click handler to open the user hero for usernames in member and state events
This commit is contained in:
1 parent
28d8e942ac
commit
b7d56d28fd
3 files changed
+39
-5
No files matched your search
+5
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: minor
|
||||
---
|
||||
|
||||
# Add ability to click on usernames in member and state events to view user info
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MouseEventHandler, useMemo } from 'react';
|
||||
import { MouseEventHandler, useCallback, useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import {
|
||||
@@ -20,6 +20,7 @@ import { useMemberEventParser } from '$hooks/useMemberEventParser';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { useMatrixEventRenderer } from '$hooks/useMatrixEventRenderer';
|
||||
import { useOpenUserRoomProfile } from '$state/hooks/userRoomProfile';
|
||||
import {
|
||||
EventContent,
|
||||
ImageContent,
|
||||
@@ -58,9 +59,25 @@ import { useSableCosmetics } from '$hooks/useSableCosmetics';
|
||||
|
||||
function DecoratedUser({ room, userId, userName }: DecoratedUserProps) {
|
||||
const { color, font } = useSableCosmetics(userId, room ?? ({} as Room));
|
||||
|
||||
const openUserRoomProfile = useOpenUserRoomProfile();
|
||||
const handleUserClick: MouseEventHandler = useCallback(
|
||||
(evt) => {
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
openUserRoomProfile(
|
||||
room.roomId,
|
||||
undefined,
|
||||
userId,
|
||||
evt.currentTarget.getBoundingClientRect()
|
||||
);
|
||||
},
|
||||
[room, userId, openUserRoomProfile]
|
||||
);
|
||||
|
||||
return (
|
||||
<Text truncate>
|
||||
<b style={{ color, font }}> {userName ?? userId} </b>
|
||||
<Text as="a" onClick={handleUserClick} truncate>
|
||||
<b style={{ color, font }}>{userName ?? userId} </b>
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { MouseEventHandler, useCallback, ReactNode } from 'react';
|
||||
import { IconSrc, Icons, Text } from 'folds';
|
||||
import { MatrixEvent, Room } from '$types/matrix-sdk';
|
||||
import { IMemberContent, Membership } from '$types/matrix/room';
|
||||
import { getMxIdLocalPart } from '$utils/matrix';
|
||||
import { isMembershipChanged } from '$utils/room';
|
||||
import { useOpenUserRoomProfile } from '$state/hooks/userRoomProfile';
|
||||
import { useSableCosmetics } from './useSableCosmetics';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
|
||||
@@ -17,8 +18,19 @@ function DecoratedUser({ roomId, userId, userName }: DecoratedUserProps) {
|
||||
const mx = useMatrixClient();
|
||||
const room = mx.getRoom(roomId);
|
||||
const { color, font } = useSableCosmetics(userId, room ?? ({} as Room));
|
||||
|
||||
const openUserRoomProfile = useOpenUserRoomProfile();
|
||||
const handleUserClick: MouseEventHandler = useCallback(
|
||||
(evt) => {
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
openUserRoomProfile(roomId, undefined, userId, evt.currentTarget.getBoundingClientRect());
|
||||
},
|
||||
[roomId, userId, openUserRoomProfile]
|
||||
);
|
||||
|
||||
return (
|
||||
<Text truncate>
|
||||
<Text as="a" onClick={handleUserClick} truncate>
|
||||
<b style={{ color, font }}>{userName ?? userId} </b>
|
||||
</Text>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user