diff --git a/src/app/components/user-profile/UserRoomProfile.tsx b/src/app/components/user-profile/UserRoomProfile.tsx index c6fa0f0e2..b7c2d7fa6 100644 --- a/src/app/components/user-profile/UserRoomProfile.tsx +++ b/src/app/components/user-profile/UserRoomProfile.tsx @@ -1,6 +1,6 @@ import { Box, Button, color, config, Menu, MenuItem, Scroll, Text, toRem } from 'folds'; -import type { CSSProperties, SyntheticEvent } from 'react'; -import { useCallback, useLayoutEffect, useMemo, useState } from 'react'; +import type { CSSProperties } from 'react'; +import { useLayoutEffect, useMemo, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useAtomValue } from 'jotai'; import type { Opts as LinkifyOpts } from 'linkifyjs'; @@ -61,6 +61,7 @@ import { IgnoredUserAlert, MutualRoomsChip, OptionsChip, ServerChip, ShareChip } import { UserHero, UserHeroName } from './UserHero'; import { KnownMembership } from '$types/matrix-sdk'; import { useRoomMemberHydration } from '$hooks/useRoomMemberHydration'; +import { useMentionClickHandler } from '$hooks/useMentionClickHandler'; import * as css from './styles.css'; import * as prefix from '$unstable/prefixes'; import type { Persona } from '$app/persona'; @@ -496,10 +497,7 @@ export function UserRoomProfile({ navigate(withSearchParam(getDirectCreatePath(), directSearchParam)); }; - // Todo eventually maybe - const mentionClickHandler = useCallback((e: SyntheticEvent) => { - e.preventDefault(); - }, []); + const mentionClickHandler = useMentionClickHandler(room.roomId); const settingsLinkBaseUrl = useSettingsLinkBaseUrl(); const linkifyOpts = useMemo( @@ -530,8 +528,17 @@ export function UserRoomProfile({ linkifyOpts, useAuthentication, handleSpoilerClick: spoilerClickHandler, + handleMentionClick: mentionClickHandler, }), - [mx, room, linkifyOpts, settingsLinkBaseUrl, useAuthentication, spoilerClickHandler] + [ + mx, + room, + linkifyOpts, + settingsLinkBaseUrl, + useAuthentication, + spoilerClickHandler, + mentionClickHandler, + ] ); const backgroundColor = fetchedProfile.heroColor ?? color.Surface.Container; diff --git a/src/app/plugins/react-custom-html-parser.test.tsx b/src/app/plugins/react-custom-html-parser.test.tsx index 01d1ef3b1..c47ccda91 100644 --- a/src/app/plugins/react-custom-html-parser.test.tsx +++ b/src/app/plugins/react-custom-html-parser.test.tsx @@ -1,4 +1,5 @@ -import { render, screen } from '@testing-library/react'; +import { fireEvent, render, screen } from '@testing-library/react'; +import type { ReactEventHandler } from 'react'; import parse from 'html-react-parser'; import { afterEach, describe, expect, it, vi } from 'vitest'; import * as customHtmlCss from '$styles/CustomHtml.css'; @@ -514,6 +515,23 @@ describe('matrix: URI mentions', () => { ); }); + it.each([ + ['matrix:u/bob:example.org', '@bob'], + ['matrix:roomid/room:example.org', '#Lobby'], + ])('routes a matrix: %s mention through the click handler', (href, label) => { + const handleMentionClick = vi.fn>(); + const parserOptions = getReactCustomHtmlParser(roomMx(), '!room:example.com', { + settingsLinkBaseUrl, + linkifyOpts: LINKIFY_OPTS, + handleMentionClick, + }); + + render(
{parse(`${href}`, parserOptions)}
); + + fireEvent.click(screen.getByRole('link', { name: label })); + expect(handleMentionClick).toHaveBeenCalledOnce(); + }); + it('renders a matrix: room URI with via servers and falls back to the room name', () => { renderParsedHtml( 'matrix:roomid/room:example.org?via=elsewhere.ca',