From 85e8d276979e2899501738328b513a1dc92ac45b Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Thu, 9 Mar 2023 12:48:36 +0100 Subject: [PATCH] Extract avatars from permalink hook (#10328) --- src/components/views/elements/Pill.tsx | 35 +++++++++--- .../{usePermalink.tsx => usePermalink.ts} | 57 ++++++++++++------- test/components/views/elements/Pill-test.tsx | 22 ++++++- .../elements/__snapshots__/Pill-test.tsx.snap | 40 +++++++++++++ 4 files changed, 126 insertions(+), 28 deletions(-) rename src/hooks/{usePermalink.tsx => usePermalink.ts} (76%) diff --git a/src/components/views/elements/Pill.tsx b/src/components/views/elements/Pill.tsx index 3a14f7b634..1ccc3f36b5 100644 --- a/src/components/views/elements/Pill.tsx +++ b/src/components/views/elements/Pill.tsx @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import React, { useState } from "react"; +import React, { ReactElement, useState } from "react"; import classNames from "classnames"; import { Room } from "matrix-js-sdk/src/models/room"; @@ -22,6 +22,8 @@ import { MatrixClientPeg } from "../../../MatrixClientPeg"; import MatrixClientContext from "../../../contexts/MatrixClientContext"; import Tooltip, { Alignment } from "../elements/Tooltip"; import { usePermalink } from "../../../hooks/usePermalink"; +import RoomAvatar from "../avatars/RoomAvatar"; +import MemberAvatar from "../avatars/MemberAvatar"; export enum PillType { UserMention = "TYPE_USER_MENTION", @@ -52,13 +54,13 @@ export interface PillProps { export const Pill: React.FC = ({ type: propType, url, inMessage, room, shouldShowPillAvatar }) => { const [hover, setHover] = useState(false); - const { avatar, onClick, resourceId, text, type } = usePermalink({ + const { member, onClick, resourceId, targetRoom, text, type } = usePermalink({ room, type: propType, url, }); - if (!type) { + if (!type || !text) { return null; } @@ -79,6 +81,27 @@ export const Pill: React.FC = ({ type: propType, url, inMessage, room }; const tip = hover && resourceId ? : null; + let avatar: ReactElement | null = null; + + switch (type) { + case PillType.AtRoomMention: + case PillType.RoomMention: + case "space": + avatar = targetRoom ?