From 0d100cbbce0d3ea4b3c8e9503befd1a5837503c2 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Fri, 1 Jul 2022 21:01:18 +0200 Subject: [PATCH] Render HTML topics in rooms on space home (#8939) * Render HTML topics in rooms on space home Signed-off-by: Johannes Marbach * Add type annotations Signed-off-by: Johannes Marbach * Remove superfluous conditional check Signed-off-by: Johannes Marbach --- src/components/structures/SpaceHierarchy.tsx | 25 +++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/components/structures/SpaceHierarchy.tsx b/src/components/structures/SpaceHierarchy.tsx index 9d7c737c5f2..cb0432efb5d 100644 --- a/src/components/structures/SpaceHierarchy.tsx +++ b/src/components/structures/SpaceHierarchy.tsx @@ -18,6 +18,7 @@ import React, { Dispatch, KeyboardEvent, KeyboardEventHandler, + ReactElement, ReactNode, SetStateAction, useCallback, @@ -50,7 +51,7 @@ import TextWithTooltip from "../views/elements/TextWithTooltip"; import { useStateToggle } from "../../hooks/useStateToggle"; import { getChildOrder } from "../../stores/spaces/SpaceStore"; import AccessibleTooltipButton from "../views/elements/AccessibleTooltipButton"; -import { linkifyElement } from "../../HtmlUtils"; +import { linkifyElement, topicToHtml } from "../../HtmlUtils"; import { useDispatcher } from "../../hooks/useDispatcher"; import { Action } from "../../dispatcher/actions"; import { IState, RovingTabIndexProvider, useRovingTabIndex } from "../../accessibility/RovingTabIndex"; @@ -65,6 +66,7 @@ import { JoinRoomReadyPayload } from "../../dispatcher/payloads/JoinRoomReadyPay import { KeyBindingAction } from "../../accessibility/KeyboardShortcuts"; import { getKeyBindingsManager } from "../../KeyBindingsManager"; import { Alignment } from "../views/elements/Tooltip"; +import { getTopic } from "../../hooks/room/useTopic"; interface IProps { space: Room; @@ -122,7 +124,7 @@ const Tile: React.FC = ({ }); }; - let button; + let button: ReactElement; if (busy) { button = = ({ ; } - let checkbox; + let checkbox: ReactElement | undefined; if (onToggleClick) { if (hasPermissions) { checkbox = ; @@ -168,7 +170,7 @@ const Tile: React.FC = ({ } } - let avatar; + let avatar: ReactElement; if (joinedRoom) { avatar = ; } else { @@ -186,19 +188,22 @@ const Tile: React.FC = ({ description += " · " + _t("%(count)s rooms", { count: numChildRooms }); } - const topic = joinedRoom?.currentState?.getStateEvents(EventType.RoomTopic, "")?.getContent()?.topic || room.topic; - if (topic) { - description += " · " + topic; + let topic: ReactNode | string | null; + if (joinedRoom) { + const topicObj = getTopic(joinedRoom); + topic = topicToHtml(topicObj?.text, topicObj?.html); + } else { + topic = room.topic; } - let joinedSection; + let joinedSection: ReactElement | undefined; if (joinedRoom) { joinedSection =
{ _t("Joined") }
; } - let suggestedSection; + let suggestedSection: ReactElement | undefined; if (suggested && (!joinedRoom || hasPermissions)) { suggestedSection = { _t("Suggested") } @@ -226,6 +231,8 @@ const Tile: React.FC = ({ }} > { description } + { topic && " · " } + { topic }