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

Commit

Permalink
Render HTML topics in rooms on space home (#8939)
Browse files Browse the repository at this point in the history
* Render HTML topics in rooms on space home

Signed-off-by: Johannes Marbach <[email protected]>

* Add type annotations

Signed-off-by: Johannes Marbach <[email protected]>

* Remove superfluous conditional check

Signed-off-by: Johannes Marbach <[email protected]>
  • Loading branch information
Johennes authored Jul 1, 2022
1 parent 933ced5 commit 0d100cb
Showing 1 changed file with 16 additions and 9 deletions.
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

0 comments on commit 0d100cb

Please sign in to comment.