Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 130bcd1

Browse files
authored
Allow adding extra icons to the room header (#22)
1 parent dae6a5a commit 130bcd1

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

src/lifecycles/RoomViewLifecycle.ts

+14
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,29 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
import React from "react";
18+
1719
export enum RoomViewLifecycle {
1820
PreviewRoomNotLoggedIn = "preview_not_logged_in",
1921
JoinFromRoomPreview = "try_join_not_logged_in",
22+
ViewRoom = "view_room",
2023
}
2124

2225
export type RoomPreviewOpts = {
2326
canJoin: boolean;
2427
};
2528

29+
export type ViewRoomOpts = {
30+
buttons: Array<{
31+
icon: React.ReactNode;
32+
id: string;
33+
label: () => string;
34+
onClick: () => void;
35+
}>;
36+
};
37+
2638
export type RoomPreviewListener = (opts: RoomPreviewOpts, roomId: string) => void;
2739

2840
export type JoinFromPreviewListener = (roomId: string) => void;
41+
42+
export type ViewRoomListener = (opts: ViewRoomOpts, roomId: string) => void;
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright 2023 Nordeck IT + Consulting GmbH
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { RuntimeModule } from "../../src";
18+
import { ViewRoomListener, ViewRoomOpts, RoomViewLifecycle } from "../../src/lifecycles/RoomViewLifecycle";
19+
20+
describe("RoomViewLifecycle", () => {
21+
const roomHeaderOpts: ViewRoomOpts = {
22+
buttons: [
23+
{
24+
icon: "test-icon",
25+
id: "test-id",
26+
label: () => "test-label",
27+
onClick: () => {},
28+
},
29+
],
30+
};
31+
32+
let module: RuntimeModule;
33+
34+
beforeAll(() => {
35+
module = new (class extends RuntimeModule {
36+
public constructor() {
37+
super(undefined as any);
38+
39+
this.on(RoomViewLifecycle.ViewRoom, this.renderRoomHeaderListener);
40+
}
41+
42+
protected renderRoomHeaderListener: ViewRoomListener = (opts, roomId) => {
43+
opts.buttons = roomHeaderOpts.buttons;
44+
};
45+
})();
46+
});
47+
48+
it("should handle additional buttons", () => {
49+
const opts: ViewRoomOpts = { buttons: [] };
50+
module.emit(RoomViewLifecycle.ViewRoom, opts);
51+
expect(opts).toEqual(roomHeaderOpts);
52+
});
53+
});

0 commit comments

Comments
 (0)