From 533eda2273fad4ca280d3f38639c2ce358d3d3fe Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Wed, 12 Oct 2022 16:00:37 +0200 Subject: [PATCH] Extract voice broadcast header (#9393) --- res/css/_components.pcss | 1 + res/css/components/atoms/_Icon.pcss | 4 + .../atoms/_VoiceBroadcastHeader.pcss | 44 +++++++ src/components/atoms/Icon.tsx | 1 + src/i18n/strings/en_EN.json | 2 +- .../components/VoiceBroadcastBody.tsx | 7 +- .../components/atoms/VoiceBroadcastHeader.tsx | 55 +++++++++ .../molecules/VoiceBroadcastRecordingBody.tsx | 29 ++--- src/voice-broadcast/index.ts | 1 + .../components/VoiceBroadcastBody-test.tsx | 18 ++- .../atoms/VoiceBroadcastHeader-test.tsx | 60 ++++++++++ .../VoiceBroadcastHeader-test.tsx.snap | 109 ++++++++++++++++++ .../VoiceBroadcastRecordingBody-test.tsx | 40 +++---- .../VoiceBroadcastRecordingBody-test.tsx.snap | 26 +---- 14 files changed, 318 insertions(+), 79 deletions(-) create mode 100644 res/css/voice-broadcast/atoms/_VoiceBroadcastHeader.pcss create mode 100644 src/voice-broadcast/components/atoms/VoiceBroadcastHeader.tsx create mode 100644 test/voice-broadcast/components/atoms/VoiceBroadcastHeader-test.tsx create mode 100644 test/voice-broadcast/components/atoms/__snapshots__/VoiceBroadcastHeader-test.tsx.snap diff --git a/res/css/_components.pcss b/res/css/_components.pcss index efb3e9e594..faaf208948 100644 --- a/res/css/_components.pcss +++ b/res/css/_components.pcss @@ -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"; diff --git a/res/css/components/atoms/_Icon.pcss b/res/css/components/atoms/_Icon.pcss index 08a72d3d5b..1db3278fe9 100644 --- a/res/css/components/atoms/_Icon.pcss +++ b/res/css/components/atoms/_Icon.pcss @@ -32,3 +32,7 @@ limitations under the License. .mx_Icon_live-badge { background-color: #fff; } + +.mx_Icon_compound-secondary-content { + background-color: $secondary-content; +} diff --git a/res/css/voice-broadcast/atoms/_VoiceBroadcastHeader.pcss b/res/css/voice-broadcast/atoms/_VoiceBroadcastHeader.pcss new file mode 100644 index 0000000000..dc1522811c --- /dev/null +++ b/res/css/voice-broadcast/atoms/_VoiceBroadcastHeader.pcss @@ -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-4; +} diff --git a/src/components/atoms/Icon.tsx b/src/components/atoms/Icon.tsx index bb6ea61524..6ec0194cc9 100644 --- a/src/components/atoms/Icon.tsx +++ b/src/components/atoms/Icon.tsx @@ -29,6 +29,7 @@ const iconTypeMap = new Map([ export enum IconColour { Accent = "accent", LiveBadge = "live-badge", + CompoundSecondaryContent = "compound-secondary-content", } export enum IconSize { diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 5bd66ec9a3..4b759ca21e 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -637,6 +637,7 @@ "See %(msgtype)s messages posted to this room": "See %(msgtype)s messages posted to this room", "See %(msgtype)s messages posted to your active room": "See %(msgtype)s messages posted to your active room", "Live": "Live", + "Voice broadcast": "Voice broadcast", "Cannot reach homeserver": "Cannot reach homeserver", "Ensure you have a stable internet connection, or get in touch with the server admin": "Ensure you have a stable internet connection, or get in touch with the server admin", "Your %(brand)s is misconfigured": "Your %(brand)s is misconfigured", @@ -1850,7 +1851,6 @@ "Emoji": "Emoji", "Hide stickers": "Hide stickers", "Sticker": "Sticker", - "Voice broadcast": "Voice broadcast", "Voice Message": "Voice Message", "You do not have permission to start polls in this room.": "You do not have permission to start polls in this room.", "Poll": "Poll", diff --git a/src/voice-broadcast/components/VoiceBroadcastBody.tsx b/src/voice-broadcast/components/VoiceBroadcastBody.tsx index 3591325585..e36460b9f3 100644 --- a/src/voice-broadcast/components/VoiceBroadcastBody.tsx +++ b/src/voice-broadcast/components/VoiceBroadcastBody.tsx @@ -46,13 +46,10 @@ export const VoiceBroadcastBody: React.FC = ({ mxEvent }) => { recording.stop(); }; - const senderId = mxEvent.getSender(); - const sender = mxEvent.sender; return ; }; diff --git a/src/voice-broadcast/components/atoms/VoiceBroadcastHeader.tsx b/src/voice-broadcast/components/atoms/VoiceBroadcastHeader.tsx new file mode 100644 index 0000000000..d7175db30b --- /dev/null +++ b/src/voice-broadcast/components/atoms/VoiceBroadcastHeader.tsx @@ -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 = ({ + live, + sender, + roomName, + showBroadcast = false, +}) => { + const broadcast = showBroadcast + ?
+ + { _t("Voice broadcast") } +
+ : null; + const liveBadge = live ? : null; + return
+ +
+
+ { sender.name } +
+
+ { roomName } +
+ { broadcast } +
+ { liveBadge } +
; +}; diff --git a/src/voice-broadcast/components/molecules/VoiceBroadcastRecordingBody.tsx b/src/voice-broadcast/components/molecules/VoiceBroadcastRecordingBody.tsx index 13ea504ac4..0db9bb92e1 100644 --- a/src/voice-broadcast/components/molecules/VoiceBroadcastRecordingBody.tsx +++ b/src/voice-broadcast/components/molecules/VoiceBroadcastRecordingBody.tsx @@ -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; - title: string; - userId: string; + roomName: string; + sender: RoomMember; } export const VoiceBroadcastRecordingBody: React.FC = ({ live, - member, onClick, - title, - userId, + roomName, + sender, }) => { - const liveBadge = live - ? - : null; - return (
- -
-
- { title } -
-
- { liveBadge } +
); }; diff --git a/src/voice-broadcast/index.ts b/src/voice-broadcast/index.ts index 2765cf4f25..81f47a29ba 100644 --- a/src/voice-broadcast/index.ts +++ b/src/voice-broadcast/index.ts @@ -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"; diff --git a/test/voice-broadcast/components/VoiceBroadcastBody-test.tsx b/test/voice-broadcast/components/VoiceBroadcastBody-test.tsx index 2c94ea6d0b..d6f9da6a68 100644 --- a/test/voice-broadcast/components/VoiceBroadcastBody-test.tsx +++ b/test/voice-broadcast/components/VoiceBroadcastBody-test.tsx @@ -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, }, {}, ); @@ -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, }, {}, ); @@ -105,17 +103,17 @@ describe("VoiceBroadcastBody", () => { mocked(VoiceBroadcastRecordingBody).mockImplementation( ({ live, - member: _member, + sender, onClick, - title, - userId: _userId, + roomName, }) => { return (
-
{ title }
+
{ sender.name }
+
{ roomName }
{ live && "Live" }
); diff --git a/test/voice-broadcast/components/atoms/VoiceBroadcastHeader-test.tsx b/test/voice-broadcast/components/atoms/VoiceBroadcastHeader-test.tsx new file mode 100644 index 0000000000..6b07b213f7 --- /dev/null +++ b/test/voice-broadcast/components/atoms/VoiceBroadcastHeader-test.tsx @@ -0,0 +1,60 @@ +/* +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 { VoiceBroadcastHeader } from "../../../../src/voice-broadcast"; + +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(); + }; + + 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(); + }); + }); +}); diff --git a/test/voice-broadcast/components/atoms/__snapshots__/VoiceBroadcastHeader-test.tsx.snap b/test/voice-broadcast/components/atoms/__snapshots__/VoiceBroadcastHeader-test.tsx.snap new file mode 100644 index 0000000000..3e3bd2b1d2 --- /dev/null +++ b/test/voice-broadcast/components/atoms/__snapshots__/VoiceBroadcastHeader-test.tsx.snap @@ -0,0 +1,109 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`VoiceBroadcastHeader when rendering a live broadcast header with broadcast info should render the header with a live badge 1`] = ` +
+
+ + + + +
+
+ test user +
+
+ test room +
+
+