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

Commit

Permalink
Handle permalinks in room topic
Browse files Browse the repository at this point in the history
  • Loading branch information
Johennes committed Jun 20, 2023
1 parent 985bde7 commit b549004
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/components/views/elements/RoomTopic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import MatrixClientContext from "../../../contexts/MatrixClientContext";
import AccessibleButton from "./AccessibleButton";
import TooltipTarget from "./TooltipTarget";
import { Linkify, topicToHtml } from "../../../HtmlUtils";
import { tryTransformPermalinkToLocalHref } from "../../../utils/permalinks/Permalinks";

interface IProps extends React.HTMLProps<HTMLDivElement> {
room: Room;
Expand All @@ -46,12 +47,27 @@ export default function RoomTopic({ room, ...props }: IProps): JSX.Element {
const onClick = useCallback(
(e: React.MouseEvent<HTMLDivElement>) => {
props.onClick?.(e);

const target = e.target as HTMLElement;
if (target.tagName.toUpperCase() === "A") {

if (target.tagName.toUpperCase() !== "A") {
dis.fire(Action.ShowRoomTopic);
return;
}

const anchor: HTMLLinkElement | null = e.target as HTMLLinkElement;

if (!anchor) {
return;
}

dis.fire(Action.ShowRoomTopic);
const localHref = tryTransformPermalinkToLocalHref(anchor.href);

if (localHref !== anchor.href) {
// it could be converted to a localHref -> therefore handle locally
e.preventDefault();
window.location.hash = localHref;
}
},
[props],
);
Expand Down

0 comments on commit b549004

Please sign in to comment.