feat: overwrite room name component

pull/26786/head
Badi Ifaoui 2023-11-29 14:34:28 +01:00 committed by Badi Ifaoui
parent c0b4a00a54
commit 361fb2ebba
3 changed files with 47 additions and 2 deletions

View File

@ -4,5 +4,6 @@
"src/components/views/auth/AuthPage.tsx": "src/components/views/auth/VectorAuthPage.tsx",
"src/components/views/rooms/Autocomplete.tsx": "src/components/views/rooms/Autocomplete.tsx",
"src/components/views/rooms/RoomTile.tsx": "src/components/views/rooms/RoomTile.tsx",
"src/components/views/elements/RoomName.tsx": "src/components/views/elements/RoomName.tsx",
"src/editor/commands.tsx": "src/editor/commands.tsx"
}

View File

@ -0,0 +1,44 @@
/*
Copyright 2021 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import React, { useEffect, useState } from "react";
import { Room, RoomEvent } from "matrix-js-sdk/src/matrix";
import { useTypedEventEmitter } from "matrix-react-sdk/src/hooks/useEventEmitter";
import { getRoomName } from "../../../hooks/useTokengatedRoom";
interface IProps {
room?: Room;
children?(name: string): JSX.Element;
}
/**
* @deprecated use `useRoomName.ts` instead
*/
const RoomName = ({ room, children }: IProps): JSX.Element => {
const [name, setName] = useState(getRoomName(room));
useTypedEventEmitter(room, RoomEvent.Name, () => {
setName(getRoomName(room));
});
useEffect(() => {
setName(getRoomName(room));
}, [room]);
if (children) return children(name ?? "");
return <>{name || ""}</>;
};
export default RoomName;

View File

@ -1,7 +1,7 @@
import { Room } from "matrix-js-sdk/src/matrix";
import { useMemo } from "react";
export function getRoomName(room: Room): string {
export function getRoomName(room?: Room): string {
return (room?.name || "")
.replace(":", ":\u200b") // add a zero-width space to allow linewrapping after the colon (matrix defaults)
.replace("[TG]", "");
@ -11,7 +11,7 @@ export function isTokenGatedRoom(room: Room): boolean {
return room?.name?.includes("[TG]");
}
export function useTokenGatedRoom(room: Room): any {
export function useTokenGatedRoom(room: Room): { roomName: string; isVerifiedRoom: boolean } {
const roomName = useMemo(() => {
return getRoomName(room);
}, [room]);