Linkify room topic (#11631)
This commit is contained in:
parent
1c16eab1cd
commit
fc9caa3269
3 changed files with 15 additions and 2 deletions
|
@ -47,6 +47,7 @@ import { useRoomState } from "../../../hooks/useRoomState";
|
||||||
import RoomAvatar from "../avatars/RoomAvatar";
|
import RoomAvatar from "../avatars/RoomAvatar";
|
||||||
import { formatCount } from "../../../utils/FormattingUtils";
|
import { formatCount } from "../../../utils/FormattingUtils";
|
||||||
import RightPanelStore from "../../../stores/right-panel/RightPanelStore";
|
import RightPanelStore from "../../../stores/right-panel/RightPanelStore";
|
||||||
|
import { Linkify, topicToHtml } from "../../../HtmlUtils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper to transform a notification color to the what the Compound Icon Button
|
* A helper to transform a notification color to the what the Compound Icon Button
|
||||||
|
@ -100,6 +101,11 @@ export default function RoomHeader({ room }: { room: Room }): JSX.Element {
|
||||||
|
|
||||||
const notificationsEnabled = useFeatureEnabled("feature_notifications");
|
const notificationsEnabled = useFeatureEnabled("feature_notifications");
|
||||||
|
|
||||||
|
const roomTopicBody = useMemo(
|
||||||
|
() => topicToHtml(roomTopic?.text, roomTopic?.html),
|
||||||
|
[roomTopic?.html, roomTopic?.text],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
as="header"
|
as="header"
|
||||||
|
@ -159,7 +165,7 @@ export default function RoomHeader({ room }: { room: Room }): JSX.Element {
|
||||||
</BodyText>
|
</BodyText>
|
||||||
{roomTopic && (
|
{roomTopic && (
|
||||||
<BodyText as="div" size="sm" className="mx_RoomHeader_topic">
|
<BodyText as="div" size="sm" className="mx_RoomHeader_topic">
|
||||||
{roomTopic.text}
|
<Linkify>{roomTopicBody}</Linkify>
|
||||||
</BodyText>
|
</BodyText>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
|
|
|
@ -32,6 +32,11 @@ export const getTopic = (room?: Room): Optional<ContentHelpers.TopicState> => {
|
||||||
return !!content ? ContentHelpers.parseTopicContent(content) : null;
|
return !!content ? ContentHelpers.parseTopicContent(content) : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to retrieve the room topic for given room
|
||||||
|
* @param room
|
||||||
|
* @returns the raw text and an html parsion version of the room topic
|
||||||
|
*/
|
||||||
export function useTopic(room?: Room): Optional<ContentHelpers.TopicState> {
|
export function useTopic(room?: Room): Optional<ContentHelpers.TopicState> {
|
||||||
const [topic, setTopic] = useState(getTopic(room));
|
const [topic, setTopic] = useState(getTopic(room));
|
||||||
useTypedEventEmitter(room?.currentState, RoomStateEvent.Events, (ev: MatrixEvent) => {
|
useTypedEventEmitter(room?.currentState, RoomStateEvent.Events, (ev: MatrixEvent) => {
|
||||||
|
|
|
@ -21,6 +21,7 @@ import {
|
||||||
fireEvent,
|
fireEvent,
|
||||||
getAllByLabelText,
|
getAllByLabelText,
|
||||||
getByLabelText,
|
getByLabelText,
|
||||||
|
getByRole,
|
||||||
getByText,
|
getByText,
|
||||||
render,
|
render,
|
||||||
screen,
|
screen,
|
||||||
|
@ -78,7 +79,7 @@ describe("RoomHeader", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders the room topic", async () => {
|
it("renders the room topic", async () => {
|
||||||
const TOPIC = "Hello World!";
|
const TOPIC = "Hello World! http://element.io";
|
||||||
|
|
||||||
const roomTopic = new MatrixEvent({
|
const roomTopic = new MatrixEvent({
|
||||||
type: EventType.RoomTopic,
|
type: EventType.RoomTopic,
|
||||||
|
@ -96,6 +97,7 @@ describe("RoomHeader", () => {
|
||||||
withClientContextRenderOptions(MatrixClientPeg.get()!),
|
withClientContextRenderOptions(MatrixClientPeg.get()!),
|
||||||
);
|
);
|
||||||
expect(container).toHaveTextContent(TOPIC);
|
expect(container).toHaveTextContent(TOPIC);
|
||||||
|
expect(getByRole(container, "link")).toHaveTextContent("http://element.io");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("opens the room summary", async () => {
|
it("opens the room summary", async () => {
|
||||||
|
|
Loading…
Reference in a new issue