@@ -8,27 +8,39 @@ Please see LICENSE files in the repository root for full details.
88import React from "react" ;
99import { type RoomViewProps , type BuiltinsApi } from "@element-hq/element-web-module-api" ;
1010
11- import RoomAvatar from "../components/views/avatars/RoomAvatar" ;
1211import { MatrixClientPeg } from "../MatrixClientPeg" ;
12+ import type { Room } from "matrix-js-sdk/src/matrix" ;
1313
1414interface RoomViewPropsWithRoomId extends RoomViewProps {
1515 roomId : string ;
1616}
1717
18+ interface RoomAvatarProps {
19+ room : Room ;
20+ size ?: string ;
21+ }
22+
23+ interface Components {
24+ roomView : React . ComponentType < RoomViewPropsWithRoomId > ;
25+ roomAvatar : React . ComponentType < RoomAvatarProps > ;
26+ }
27+
1828export class ElementWebBuiltinsApi implements BuiltinsApi {
1929 private _roomView ?: React . ComponentType < RoomViewPropsWithRoomId > ;
30+ private _roomAvatar ?: React . ComponentType < RoomAvatarProps > ;
2031
2132 /**
22- * Sets the components used to render a RoomView
33+ * Sets the components used by the API.
2334 *
24- * This only really exists here because referencing RoomView directly causes a nightmare of
35+ * This only really exists here because referencing these components directly causes a nightmare of
2536 * circular dependencies that break the whole app, so instead we avoid referencing it here
2637 * and pass it in from somewhere it's already referenced (see related comment in app.tsx).
2738 *
2839 * @param component The RoomView component
2940 */
30- public setRoomViewComponent ( component : React . ComponentType < RoomViewPropsWithRoomId > ) : void {
31- this . _roomView = component ;
41+ public setComponents ( components : Components ) : void {
42+ this . _roomView = components . roomView ;
43+ this . _roomAvatar = components . roomAvatar ;
3244 }
3345
3446 public getRoomViewComponent ( ) : React . ComponentType < RoomViewPropsWithRoomId > {
@@ -39,6 +51,14 @@ export class ElementWebBuiltinsApi implements BuiltinsApi {
3951 return this . _roomView ;
4052 }
4153
54+ public getRoomAvatarComponent ( ) : React . ComponentType < RoomAvatarProps > {
55+ if ( ! this . _roomAvatar ) {
56+ throw new Error ( "No RoomAvatar component has been set" ) ;
57+ }
58+
59+ return this . _roomAvatar ;
60+ }
61+
4262 public renderRoomView ( roomId : string ) : React . ReactNode {
4363 const Component = this . getRoomViewComponent ( ) ;
4464 return < Component roomId = { roomId } /> ;
@@ -49,6 +69,7 @@ export class ElementWebBuiltinsApi implements BuiltinsApi {
4969 if ( ! room ) {
5070 throw new Error ( `No room such room: ${ roomId } ` ) ;
5171 }
52- return < RoomAvatar room = { room } size = { size } /> ;
72+ const Component = this . getRoomAvatarComponent ( ) ;
73+ return < Component room = { room } size = { size } /> ;
5374 }
5475}
0 commit comments