Render HTML topics in rooms on space home (#8939)

* Render HTML topics in rooms on space home

Signed-off-by: Johannes Marbach <johannesm@element.io>

* Add type annotations

Signed-off-by: Johannes Marbach <johannesm@element.io>

* Remove superfluous conditional check

Signed-off-by: Johannes Marbach <johannesm@element.io>
This commit is contained in:
Johannes Marbach 2022-07-01 21:01:18 +02:00 committed by GitHub
parent 933ced5043
commit 0d100cbbce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,6 +18,7 @@ import React, {
Dispatch, Dispatch,
KeyboardEvent, KeyboardEvent,
KeyboardEventHandler, KeyboardEventHandler,
ReactElement,
ReactNode, ReactNode,
SetStateAction, SetStateAction,
useCallback, useCallback,
@ -50,7 +51,7 @@ import TextWithTooltip from "../views/elements/TextWithTooltip";
import { useStateToggle } from "../../hooks/useStateToggle"; import { useStateToggle } from "../../hooks/useStateToggle";
import { getChildOrder } from "../../stores/spaces/SpaceStore"; import { getChildOrder } from "../../stores/spaces/SpaceStore";
import AccessibleTooltipButton from "../views/elements/AccessibleTooltipButton"; import AccessibleTooltipButton from "../views/elements/AccessibleTooltipButton";
import { linkifyElement } from "../../HtmlUtils"; import { linkifyElement, topicToHtml } from "../../HtmlUtils";
import { useDispatcher } from "../../hooks/useDispatcher"; import { useDispatcher } from "../../hooks/useDispatcher";
import { Action } from "../../dispatcher/actions"; import { Action } from "../../dispatcher/actions";
import { IState, RovingTabIndexProvider, useRovingTabIndex } from "../../accessibility/RovingTabIndex"; import { IState, RovingTabIndexProvider, useRovingTabIndex } from "../../accessibility/RovingTabIndex";
@ -65,6 +66,7 @@ import { JoinRoomReadyPayload } from "../../dispatcher/payloads/JoinRoomReadyPay
import { KeyBindingAction } from "../../accessibility/KeyboardShortcuts"; import { KeyBindingAction } from "../../accessibility/KeyboardShortcuts";
import { getKeyBindingsManager } from "../../KeyBindingsManager"; import { getKeyBindingsManager } from "../../KeyBindingsManager";
import { Alignment } from "../views/elements/Tooltip"; import { Alignment } from "../views/elements/Tooltip";
import { getTopic } from "../../hooks/room/useTopic";
interface IProps { interface IProps {
space: Room; space: Room;
@ -122,7 +124,7 @@ const Tile: React.FC<ITileProps> = ({
}); });
}; };
let button; let button: ReactElement;
if (busy) { if (busy) {
button = <AccessibleTooltipButton button = <AccessibleTooltipButton
disabled={true} disabled={true}
@ -154,7 +156,7 @@ const Tile: React.FC<ITileProps> = ({
</AccessibleButton>; </AccessibleButton>;
} }
let checkbox; let checkbox: ReactElement | undefined;
if (onToggleClick) { if (onToggleClick) {
if (hasPermissions) { if (hasPermissions) {
checkbox = <StyledCheckbox checked={!!selected} onChange={onToggleClick} tabIndex={isActive ? 0 : -1} />; checkbox = <StyledCheckbox checked={!!selected} onChange={onToggleClick} tabIndex={isActive ? 0 : -1} />;
@ -168,7 +170,7 @@ const Tile: React.FC<ITileProps> = ({
} }
} }
let avatar; let avatar: ReactElement;
if (joinedRoom) { if (joinedRoom) {
avatar = <RoomAvatar room={joinedRoom} width={20} height={20} />; avatar = <RoomAvatar room={joinedRoom} width={20} height={20} />;
} else { } else {
@ -186,19 +188,22 @@ const Tile: React.FC<ITileProps> = ({
description += " · " + _t("%(count)s rooms", { count: numChildRooms }); description += " · " + _t("%(count)s rooms", { count: numChildRooms });
} }
const topic = joinedRoom?.currentState?.getStateEvents(EventType.RoomTopic, "")?.getContent()?.topic || room.topic; let topic: ReactNode | string | null;
if (topic) { if (joinedRoom) {
description += " · " + topic; const topicObj = getTopic(joinedRoom);
topic = topicToHtml(topicObj?.text, topicObj?.html);
} else {
topic = room.topic;
} }
let joinedSection; let joinedSection: ReactElement | undefined;
if (joinedRoom) { if (joinedRoom) {
joinedSection = <div className="mx_SpaceHierarchy_roomTile_joined"> joinedSection = <div className="mx_SpaceHierarchy_roomTile_joined">
{ _t("Joined") } { _t("Joined") }
</div>; </div>;
} }
let suggestedSection; let suggestedSection: ReactElement | undefined;
if (suggested && (!joinedRoom || hasPermissions)) { if (suggested && (!joinedRoom || hasPermissions)) {
suggestedSection = <InfoTooltip tooltip={_t("This room is suggested as a good one to join")}> suggestedSection = <InfoTooltip tooltip={_t("This room is suggested as a good one to join")}>
{ _t("Suggested") } { _t("Suggested") }
@ -226,6 +231,8 @@ const Tile: React.FC<ITileProps> = ({
}} }}
> >
{ description } { description }
{ topic && " · " }
{ topic }
</div> </div>
</div> </div>
<div className="mx_SpaceHierarchy_actions"> <div className="mx_SpaceHierarchy_actions">