Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Render HTML topics in rooms on space home #8939

Merged
merged 3 commits into from
Jul 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/components/structures/SpaceHierarchy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import React, {
Dispatch,
KeyboardEvent,
KeyboardEventHandler,
ReactElement,
ReactNode,
SetStateAction,
useCallback,
Expand Down Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -122,7 +124,7 @@ const Tile: React.FC<ITileProps> = ({
});
};

let button;
let button: ReactElement;
if (busy) {
button = <AccessibleTooltipButton
disabled={true}
Expand Down Expand Up @@ -154,7 +156,7 @@ const Tile: React.FC<ITileProps> = ({
</AccessibleButton>;
}

let checkbox;
let checkbox: ReactElement | undefined;
if (onToggleClick) {
if (hasPermissions) {
checkbox = <StyledCheckbox checked={!!selected} onChange={onToggleClick} tabIndex={isActive ? 0 : -1} />;
Expand All @@ -168,7 +170,7 @@ const Tile: React.FC<ITileProps> = ({
}
}

let avatar;
let avatar: ReactElement;
if (joinedRoom) {
avatar = <RoomAvatar room={joinedRoom} width={20} height={20} />;
} else {
Expand All @@ -186,19 +188,22 @@ const Tile: React.FC<ITileProps> = ({
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 = <div className="mx_SpaceHierarchy_roomTile_joined">
{ _t("Joined") }
</div>;
}

let suggestedSection;
let suggestedSection: ReactElement | undefined;
if (suggested && (!joinedRoom || hasPermissions)) {
suggestedSection = <InfoTooltip tooltip={_t("This room is suggested as a good one to join")}>
{ _t("Suggested") }
Expand Down Expand Up @@ -226,6 +231,8 @@ const Tile: React.FC<ITileProps> = ({
}}
>
{ description }
{ topic && " · " }
{ topic }
</div>
</div>
<div className="mx_SpaceHierarchy_actions">
Expand Down