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

Commit

Permalink
Extract voice broadcast header
Browse files Browse the repository at this point in the history
  • Loading branch information
weeman1337 committed Oct 12, 2022
1 parent bac6e12 commit 8e3f829
Show file tree
Hide file tree
Showing 14 changed files with 314 additions and 78 deletions.
1 change: 1 addition & 0 deletions res/css/_components.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,5 @@
@import "./views/voip/_PiPContainer.pcss";
@import "./views/voip/_VideoFeed.pcss";
@import "./voice-broadcast/atoms/_LiveBadge.pcss";
@import "./voice-broadcast/atoms/_VoiceBroadcastHeader.pcss";
@import "./voice-broadcast/molecules/_VoiceBroadcastRecordingBody.pcss";
1 change: 1 addition & 0 deletions res/css/_spacing.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
/* 1rem :: 10px */

$spacing-4: 4px;
$spacing-6: 6px;
$spacing-8: 8px;
$spacing-12: 12px;
$spacing-16: 16px;
Expand Down
4 changes: 4 additions & 0 deletions res/css/components/atoms/_Icon.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ limitations under the License.
.mx_Icon_live-badge {
background-color: #fff;
}

.mx_Icon_compound-secondary-content {
background-color: $secondary-content;
}
44 changes: 44 additions & 0 deletions res/css/voice-broadcast/atoms/_VoiceBroadcastHeader.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2022 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.
*/

.mx_VoiceBroadcastHeader {
align-items: flex-start;
display: flex;
gap: $spacing-8;
line-height: 20px;
margin-bottom: $spacing-8;
width: 266px;
}

.mx_VoiceBroadcastHeader_sender {
font-size: $font-12px;
font-weight: $font-semi-bold;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.mx_VoiceBroadcastHeader_room {
font-size: $font-12px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.mx_VoiceBroadcastHeader_line {
align-items: center;
color: $secondary-content;
font-size: $font-12px;
display: flex;
gap: $spacing-6;
}
1 change: 1 addition & 0 deletions src/components/atoms/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const iconTypeMap = new Map([
export enum IconColour {
Accent = "accent",
LiveBadge = "live-badge",
CompoundSecondaryContent = "compound-secondary-content",
}

export enum IconSize {
Expand Down
7 changes: 2 additions & 5 deletions src/voice-broadcast/components/VoiceBroadcastBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,10 @@ export const VoiceBroadcastBody: React.FC<IBodyProps> = ({ mxEvent }) => {
recording.stop();
};

const senderId = mxEvent.getSender();
const sender = mxEvent.sender;
return <VoiceBroadcastRecordingBody
onClick={stopVoiceBroadcast}
live={recordingState === VoiceBroadcastInfoState.Started}
member={sender}
userId={senderId}
title={`${sender?.name ?? senderId}${room.name}`}
sender={mxEvent.sender}
roomName={room.name}
/>;
};
55 changes: 55 additions & 0 deletions src/voice-broadcast/components/atoms/VoiceBroadcastHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright 2022 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 from "react";
import { RoomMember } from "matrix-js-sdk/src/matrix";

import MemberAvatar from "../../../components/views/avatars/MemberAvatar";
import { LiveBadge } from "../..";
import { Icon, IconColour, IconType } from "../../../components/atoms/Icon";
import { _t } from "../../../languageHandler";

interface VoiceBroadcastHeaderProps {
live: boolean;
sender: RoomMember;
roomName: string;
showBroadcast?: boolean;
}

export const VoiceBroadcastHeader: React.FC<VoiceBroadcastHeaderProps> = ({
live,
sender,
roomName,
showBroadcast = false,
}) => {
const broadcast = showBroadcast
? <div className="mx_VoiceBroadcastHeader_line">
<Icon type={IconType.Live} colour={IconColour.CompoundSecondaryContent} />
{ _t("Voice broadcast") }
</div>
: null;
const liveBadge = live ? <LiveBadge /> : null;
return <div className="mx_VoiceBroadcastHeader">
<MemberAvatar member={sender} fallbackUserId={sender.userId} />
<div className="mx_VoiceBroadcastHeader_content">
<div className="mx_VoiceBroadcastHeader_sender">
{ sender.name }
</div>
<div className="mx_VoiceBroadcastHeader_room">
{ roomName }
</div>
{ broadcast }
</div>
{ liveBadge }
</div>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,31 @@ limitations under the License.
import React, { MouseEventHandler } from "react";
import { RoomMember } from "matrix-js-sdk/src/matrix";

import { LiveBadge } from "../..";
import MemberAvatar from "../../../components/views/avatars/MemberAvatar";
import { VoiceBroadcastHeader } from "../..";

interface VoiceBroadcastRecordingBodyProps {
live: boolean;
member: RoomMember;
onClick: MouseEventHandler<HTMLDivElement>;
title: string;
userId: string;
roomName: string;
sender: RoomMember;
}

export const VoiceBroadcastRecordingBody: React.FC<VoiceBroadcastRecordingBodyProps> = ({
live,
member,
onClick,
title,
userId,
roomName,
sender,
}) => {
const liveBadge = live
? <LiveBadge />
: null;

return (
<div
className="mx_VoiceBroadcastRecordingBody"
onClick={onClick}
>
<MemberAvatar member={member} fallbackUserId={userId} />
<div className="mx_VoiceBroadcastRecordingBody_content">
<div className="mx_VoiceBroadcastRecordingBody_title">
{ title }
</div>
</div>
{ liveBadge }
<VoiceBroadcastHeader
live={live}
sender={sender}
roomName={roomName}
/>
</div>
);
};
1 change: 1 addition & 0 deletions src/voice-broadcast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { RelationType } from "matrix-js-sdk/src/matrix";
export * from "./audio/VoiceBroadcastRecorder";
export * from "./components/VoiceBroadcastBody";
export * from "./components/atoms/LiveBadge";
export * from "./components/atoms/VoiceBroadcastHeader";
export * from "./components/molecules/VoiceBroadcastRecordingBody";
export * from "./models/VoiceBroadcastRecording";
export * from "./stores/VoiceBroadcastRecordingsStore";
Expand Down
18 changes: 8 additions & 10 deletions test/voice-broadcast/components/VoiceBroadcastBody-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ describe("VoiceBroadcastBody", () => {
{
onClick: expect.any(Function),
live: true,
member: infoEvent.sender,
userId: client.getUserId(),
title: "@userId:matrix.org • test room",
sender: infoEvent.sender,
roomName: room.name,
},
{},
);
Expand All @@ -89,9 +88,8 @@ describe("VoiceBroadcastBody", () => {
{
onClick: expect.any(Function),
live: false,
member: infoEvent.sender,
userId: client.getUserId(),
title: "@userId:matrix.org • test room",
sender: infoEvent.sender,
roomName: room.name,
},
{},
);
Expand All @@ -105,17 +103,17 @@ describe("VoiceBroadcastBody", () => {
mocked(VoiceBroadcastRecordingBody).mockImplementation(
({
live,
member: _member,
sender,
onClick,
title,
userId: _userId,
roomName,
}) => {
return (
<div
data-testid={recordingTestid}
onClick={onClick}
>
<div>{ title }</div>
<div>{ sender.name }</div>
<div>{ roomName }</div>
<div>{ live && "Live" }</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
Copyright 2022 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 from "react";
import { Container } from "react-dom";
import { RoomMember } from "matrix-js-sdk/src/matrix";
import { render, RenderResult } from "@testing-library/react";

import MemberAvatar from "../../../../src/components/views/avatars/MemberAvatar";
import { VoiceBroadcastHeader } from "../../../../src/voice-broadcast";
import { Icon } from "../../../../src/components/atoms/Icon";

jest.mock("../../../../src/components/views/avatars/MemberAvatar", () => ({
__esModule: true,
default: ({ member, fallbackUserId }: React.ComponentProps<typeof MemberAvatar>) => {
return <div data-testid="member-avatar">
{ member.name },
{ fallbackUserId }
</div>;
},
}));

jest.mock("../../../../src/voice-broadcast/components/atoms/LiveBadge", () => ({
LiveBadge: () => {
return <div data-testid="live-badge" />;
},
}));

jest.mock("../../../../src/components/atoms/Icon", () => ({
...jest.requireActual("../../../../src/components/atoms/Icon") as object,
Icon: ({ type, colour }: React.ComponentProps<typeof Icon>) => {
return <div data-testid="icon">
type: { type },
colour: { colour }
</div>;
},
}));

describe("VoiceBroadcastHeader", () => {
const userId = "@user:example.com";
const roomId = "!room:example.com";
const roomName = "test room";
const sender = new RoomMember(roomId, userId);
let container: Container;

const renderHeader = (live: boolean, showBroadcast: boolean = undefined): RenderResult => {
return render(<VoiceBroadcastHeader
live={live}
sender={sender}
roomName={roomName}
showBroadcast={showBroadcast}
/>);
};

beforeAll(() => {
sender.name = "test user";
});

describe("when rendering a live broadcast header with broadcast info", () => {
beforeEach(() => {
container = renderHeader(true, true).container;
});

it("should render the header with a live badge", () => {
expect(container).toMatchSnapshot();
});
});

describe("when rendering a non-live broadcast header", () => {
beforeEach(() => {
container = renderHeader(false).container;
});

it("should render the header without a live badge", () => {
expect(container).toMatchSnapshot();
});
});
});
Loading

0 comments on commit 8e3f829

Please sign in to comment.