From d551469543c97202d5115c86c8a81ca96d1a62d0 Mon Sep 17 00:00:00 2001 From: Germain Date: Fri, 1 Sep 2023 10:45:50 +0100 Subject: [PATCH] Room header UI updates (#11507) * Fix performance issues with useRoomMembers With the current implementation it would create a new function, with leading: true, rendering the whole throttling useless * Add public room indicator * Format room members count better * Add public room test * Add search to room summary card * Update settings UI * Update snapshot * Remove default title attribute --- res/css/_common.pcss | 8 +++++ .../views/right_panel/_RoomSummaryCard.pcss | 4 +++ res/css/views/rooms/_RoomHeader.pcss | 6 ++++ src/components/structures/RightPanel.tsx | 2 ++ src/components/structures/RoomView.tsx | 1 + src/components/views/avatars/BaseAvatar.tsx | 2 +- .../views/right_panel/RoomSummaryCard.tsx | 11 +++++- src/components/views/rooms/RoomHeader.tsx | 30 ++++++++++++---- src/hooks/useRoomMembers.ts | 31 +++++++++-------- src/i18n/strings/en_EN.json | 5 +-- src/settings/Settings.tsx | 1 + .../__snapshots__/RoomView-test.tsx.snap | 14 ++++---- .../SpaceHierarchy-test.tsx.snap | 8 ++--- .../__snapshots__/UserMenu-test.tsx.snap | 2 +- .../__snapshots__/RoomAvatar-test.tsx.snap | 6 ++-- ...nageRestrictedJoinRuleDialog-test.tsx.snap | 2 +- .../__snapshots__/AppTile-test.tsx.snap | 3 -- .../__snapshots__/FacePile-test.tsx.snap | 2 +- .../elements/__snapshots__/Pill-test.tsx.snap | 16 ++++----- .../__snapshots__/RoomFacePile-test.tsx.snap | 2 +- .../views/messages/TextualBody-test.tsx | 2 +- .../__snapshots__/TextualBody-test.tsx.snap | 22 +++++------- .../RoomSummaryCard-test.tsx.snap | 9 ++++- .../__snapshots__/UserInfo-test.tsx.snap | 2 +- .../views/rooms/RoomHeader-test.tsx | 22 +++++++++++- .../PinnedEventTile-test.tsx.snap | 2 +- .../__snapshots__/RoomHeader-test.tsx.snap | 34 ++++++++----------- .../RoomPreviewBar-test.tsx.snap | 8 ++--- .../__snapshots__/RoomTile-test.tsx.snap | 8 ++--- .../AddExistingToSpaceDialog-test.tsx.snap | 3 +- .../__snapshots__/HTMLExport-test.ts.snap | 4 +-- yarn.lock | 16 ++++----- 32 files changed, 176 insertions(+), 112 deletions(-) diff --git a/res/css/_common.pcss b/res/css/_common.pcss index a560474a0b..c24ee60a82 100644 --- a/res/css/_common.pcss +++ b/res/css/_common.pcss @@ -134,6 +134,14 @@ code { color: $muted-fg-color; } +.text-primary { + color: $primary-content; +} + +.text-secondary { + color: $secondary-content; +} + .mx_Verified { color: $e2e-verified-color; } diff --git a/res/css/views/right_panel/_RoomSummaryCard.pcss b/res/css/views/right_panel/_RoomSummaryCard.pcss index 0c11cab73b..ec3911c17f 100644 --- a/res/css/views/right_panel/_RoomSummaryCard.pcss +++ b/res/css/views/right_panel/_RoomSummaryCard.pcss @@ -268,3 +268,7 @@ limitations under the License. .mx_RoomSummaryCard_icon_poll::before { mask-image: url("$(res)/img/element-icons/room/composer/poll.svg"); } + +.mx_RoomSummaryCard_icon_search::before { + mask-image: url("$(res)/img/element-icons/room/search-inset.svg"); +} diff --git a/res/css/views/rooms/_RoomHeader.pcss b/res/css/views/rooms/_RoomHeader.pcss index edb596aa29..2614e1713a 100644 --- a/res/css/views/rooms/_RoomHeader.pcss +++ b/res/css/views/rooms/_RoomHeader.pcss @@ -26,6 +26,12 @@ limitations under the License. flex: 1; } +.mx_RoomHeader_heading { + display: flex; + gap: var(--cpd-space-1x); + align-items: center; +} + .mx_RoomHeader_topic { height: 0; opacity: 0; diff --git a/src/components/structures/RightPanel.tsx b/src/components/structures/RightPanel.tsx index fa4269b312..c9d64df968 100644 --- a/src/components/structures/RightPanel.tsx +++ b/src/components/structures/RightPanel.tsx @@ -57,6 +57,7 @@ interface RoomlessProps extends BaseProps { interface RoomProps extends BaseProps { room: Room; permalinkCreator: RoomPermalinkCreator; + onSearchClick?: () => void; } type Props = XOR; @@ -293,6 +294,7 @@ export default class RightPanel extends React.Component { onClose={this.onClose} // whenever RightPanel is passed a room it is passed a permalinkcreator permalinkCreator={this.props.permalinkCreator!} + onSearchClick={this.props.onSearchClick} /> ); } diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index e8521aee24..59906c5a74 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -2443,6 +2443,7 @@ export class RoomView extends React.Component { resizeNotifier={this.props.resizeNotifier} permalinkCreator={this.permalinkCreator} e2eStatus={this.state.e2eStatus} + onSearchClick={this.onSearchClick} /> ) : undefined; diff --git a/src/components/views/avatars/BaseAvatar.tsx b/src/components/views/avatars/BaseAvatar.tsx index 40932cf724..d01a5affe0 100644 --- a/src/components/views/avatars/BaseAvatar.tsx +++ b/src/components/views/avatars/BaseAvatar.tsx @@ -99,7 +99,7 @@ const BaseAvatar: React.FC = (props) => { const { name, idName, - title = "", + title, url, urls, size = "40px", diff --git a/src/components/views/right_panel/RoomSummaryCard.tsx b/src/components/views/right_panel/RoomSummaryCard.tsx index 94c2069af4..2fbccfb57f 100644 --- a/src/components/views/right_panel/RoomSummaryCard.tsx +++ b/src/components/views/right_panel/RoomSummaryCard.tsx @@ -58,6 +58,7 @@ interface IProps { room: Room; permalinkCreator: RoomPermalinkCreator; onClose(): void; + onSearchClick?: () => void; } interface IAppsSectionProps { @@ -272,7 +273,7 @@ const onRoomSettingsClick = (ev: ButtonEvent): void => { PosthogTrackers.trackInteraction("WebRightPanelRoomInfoSettingsButton", ev); }; -const RoomSummaryCard: React.FC = ({ room, permalinkCreator, onClose }) => { +const RoomSummaryCard: React.FC = ({ room, permalinkCreator, onClose, onSearchClick }) => { const cli = useContext(MatrixClientContext); const onShareRoomClick = (): void => { @@ -342,6 +343,14 @@ const RoomSummaryCard: React.FC = ({ room, permalinkCreator, onClose }) {_t("common|people")} {memberCount} + {!isVideoRoom && ( @@ -276,7 +276,7 @@ exports[`RoomView for a local room in state NEW should match the snapshot 1`] = data-type="round" role="presentation" style="--cpd-avatar-size: 24px;" - title="" + title="@user:example.com" > u @@ -356,7 +356,7 @@ exports[`RoomView for a local room in state NEW should match the snapshot 1`] = data-type="round" role="button" style="--cpd-avatar-size: 52px;" - title="" + title="@user:example.com" > u @@ -520,7 +520,7 @@ exports[`RoomView for a local room in state NEW that is encrypted should match t data-type="round" role="presentation" style="--cpd-avatar-size: 24px;" - title="" + title="@user:example.com" > u @@ -599,7 +599,7 @@ exports[`RoomView for a local room in state NEW that is encrypted should match t data-type="round" role="button" style="--cpd-avatar-size: 52px;" - title="" + title="@user:example.com" > u diff --git a/test/components/structures/__snapshots__/SpaceHierarchy-test.tsx.snap b/test/components/structures/__snapshots__/SpaceHierarchy-test.tsx.snap index 1e7edb176c..407bf372bc 100644 --- a/test/components/structures/__snapshots__/SpaceHierarchy-test.tsx.snap +++ b/test/components/structures/__snapshots__/SpaceHierarchy-test.tsx.snap @@ -77,7 +77,7 @@ exports[`SpaceHierarchy renders 1`] = ` data-type="round" role="presentation" style="--cpd-avatar-size: 20px;" - title="" + title="room-id-2" > U @@ -148,7 +148,7 @@ exports[`SpaceHierarchy renders 1`] = ` data-type="round" role="presentation" style="--cpd-avatar-size: 20px;" - title="" + title="room-id-3" > U @@ -220,7 +220,7 @@ exports[`SpaceHierarchy renders 1`] = ` data-type="round" role="presentation" style="--cpd-avatar-size: 20px;" - title="" + title="space-id-4" > N @@ -298,7 +298,7 @@ exports[`SpaceHierarchy renders 1`] = ` data-type="round" role="presentation" style="--cpd-avatar-size: 20px;" - title="" + title="room-id-5" > N diff --git a/test/components/structures/__snapshots__/UserMenu-test.tsx.snap b/test/components/structures/__snapshots__/UserMenu-test.tsx.snap index d8003602f4..a445cdf303 100644 --- a/test/components/structures/__snapshots__/UserMenu-test.tsx.snap +++ b/test/components/structures/__snapshots__/UserMenu-test.tsx.snap @@ -24,7 +24,7 @@ exports[` when rendered should render as expected 1`] = ` data-type="round" role="presentation" style="--cpd-avatar-size: 32px;" - title="" + title="@userId:matrix.org" > u diff --git a/test/components/views/avatars/__snapshots__/RoomAvatar-test.tsx.snap b/test/components/views/avatars/__snapshots__/RoomAvatar-test.tsx.snap index cd545107be..f3dffc1a26 100644 --- a/test/components/views/avatars/__snapshots__/RoomAvatar-test.tsx.snap +++ b/test/components/views/avatars/__snapshots__/RoomAvatar-test.tsx.snap @@ -9,7 +9,7 @@ exports[`RoomAvatar should render as expected for a DM room 1`] = ` data-type="round" role="presentation" style="--cpd-avatar-size: 36px;" - title="" + title="@dm_user@example.com" > D @@ -25,7 +25,7 @@ exports[`RoomAvatar should render as expected for a LocalRoom 1`] = ` data-type="round" role="presentation" style="--cpd-avatar-size: 36px;" - title="" + title="@local_room_user@example.com" > l @@ -41,7 +41,7 @@ exports[`RoomAvatar should render as expected for a Room 1`] = ` data-type="round" role="presentation" style="--cpd-avatar-size: 36px;" - title="" + title="!room:example.com" > t diff --git a/test/components/views/dialogs/__snapshots__/ManageRestrictedJoinRuleDialog-test.tsx.snap b/test/components/views/dialogs/__snapshots__/ManageRestrictedJoinRuleDialog-test.tsx.snap index 0e29403ed5..bc886f39ec 100644 --- a/test/components/views/dialogs/__snapshots__/ManageRestrictedJoinRuleDialog-test.tsx.snap +++ b/test/components/views/dialogs/__snapshots__/ManageRestrictedJoinRuleDialog-test.tsx.snap @@ -77,7 +77,7 @@ exports[` should list spaces which are not par data-type="round" role="presentation" style="--cpd-avatar-size: 20px;" - title="" + title="!space:server" > O diff --git a/test/components/views/elements/__snapshots__/AppTile-test.tsx.snap b/test/components/views/elements/__snapshots__/AppTile-test.tsx.snap index 682bb61314..5f30df761f 100644 --- a/test/components/views/elements/__snapshots__/AppTile-test.tsx.snap +++ b/test/components/views/elements/__snapshots__/AppTile-test.tsx.snap @@ -120,7 +120,6 @@ exports[`AppTile for a pinned widget should render 1`] = ` loading="lazy" referrerpolicy="no-referrer" src="image-file-stub" - title="" width="20px" /> @@ -209,7 +208,6 @@ exports[`AppTile for a pinned widget should render permission request 1`] = ` loading="lazy" referrerpolicy="no-referrer" src="image-file-stub" - title="" width="20px" /> @@ -366,7 +364,6 @@ exports[`AppTile preserves non-persisted widget on container move 1`] = ` loading="lazy" referrerpolicy="no-referrer" src="image-file-stub" - title="" width="20px" /> diff --git a/test/components/views/elements/__snapshots__/FacePile-test.tsx.snap b/test/components/views/elements/__snapshots__/FacePile-test.tsx.snap index ab12a66b22..bb39ac6ba4 100644 --- a/test/components/views/elements/__snapshots__/FacePile-test.tsx.snap +++ b/test/components/views/elements/__snapshots__/FacePile-test.tsx.snap @@ -16,7 +16,7 @@ exports[` renders with a tooltip 1`] = ` data-type="round" role="presentation" style="--cpd-avatar-size: 36px;" - title="" + title="456" > 4 diff --git a/test/components/views/elements/__snapshots__/Pill-test.tsx.snap b/test/components/views/elements/__snapshots__/Pill-test.tsx.snap index a7bedd5f48..b7fb9d0380 100644 --- a/test/components/views/elements/__snapshots__/Pill-test.tsx.snap +++ b/test/components/views/elements/__snapshots__/Pill-test.tsx.snap @@ -41,7 +41,7 @@ exports[` should render the expected pill for @room 1`] = ` data-type="round" role="presentation" style="--cpd-avatar-size: 16px;" - title="" + title="!room1:example.com" > R @@ -73,7 +73,7 @@ exports[` should render the expected pill for a known user not in the room data-type="round" role="presentation" style="--cpd-avatar-size: 16px;" - title="" + title="@user2:example.com" > U @@ -105,7 +105,7 @@ exports[` should render the expected pill for a message in another room 1` data-type="round" role="presentation" style="--cpd-avatar-size: 16px;" - title="" + title="!room1:example.com" > R @@ -137,7 +137,7 @@ exports[` should render the expected pill for a message in the same room 1 data-type="round" role="presentation" style="--cpd-avatar-size: 16px;" - title="" + title="@user1:example.com" > U @@ -169,7 +169,7 @@ exports[` should render the expected pill for a room alias 1`] = ` data-type="round" role="presentation" style="--cpd-avatar-size: 16px;" - title="" + title="!room1:example.com" > R @@ -201,7 +201,7 @@ exports[` should render the expected pill for a space 1`] = ` data-type="round" role="presentation" style="--cpd-avatar-size: 16px;" - title="" + title="!space1:example.com" > S @@ -256,7 +256,7 @@ exports[` when rendering a pill for a room should render the expected pill data-type="round" role="presentation" style="--cpd-avatar-size: 16px;" - title="" + title="!room1:example.com" > R @@ -288,7 +288,7 @@ exports[` when rendering a pill for a user in the room should render as ex data-type="round" role="presentation" style="--cpd-avatar-size: 16px;" - title="" + title="@user1:example.com" > U diff --git a/test/components/views/elements/__snapshots__/RoomFacePile-test.tsx.snap b/test/components/views/elements/__snapshots__/RoomFacePile-test.tsx.snap index d77162bc53..68c82187ba 100644 --- a/test/components/views/elements/__snapshots__/RoomFacePile-test.tsx.snap +++ b/test/components/views/elements/__snapshots__/RoomFacePile-test.tsx.snap @@ -16,7 +16,7 @@ exports[` renders 1`] = ` data-type="round" role="presentation" style="--cpd-avatar-size: 28px;" - title="" + title="@bob:example.org" > b diff --git a/test/components/views/messages/TextualBody-test.tsx b/test/components/views/messages/TextualBody-test.tsx index a6b22a7412..b2e09fa48f 100644 --- a/test/components/views/messages/TextualBody-test.tsx +++ b/test/components/views/messages/TextualBody-test.tsx @@ -199,7 +199,7 @@ describe("", () => { const { container } = getComponent({ mxEvent: ev }); const content = container.querySelector(".mx_EventTile_body"); expect(content.innerHTML).toMatchInlineSnapshot( - `"Chat with Member"`, + `"Chat with Member"`, ); }); diff --git a/test/components/views/messages/__snapshots__/TextualBody-test.tsx.snap b/test/components/views/messages/__snapshots__/TextualBody-test.tsx.snap index 6c3434ce72..518e2b8299 100644 --- a/test/components/views/messages/__snapshots__/TextualBody-test.tsx.snap +++ b/test/components/views/messages/__snapshots__/TextualBody-test.tsx.snap @@ -62,7 +62,7 @@ exports[` renders formatted m.text correctly pills appear for an data-testid="avatar-img" data-type="round" style="--cpd-avatar-size: 16px;" - title="" + title="@member:domain.bla" > renders formatted m.text correctly pills appear for an loading="lazy" referrerpolicy="no-referrer" src="mxc://avatar.url/image.png" - title="@member:domain.bla" width="16px" /> @@ -113,7 +112,7 @@ exports[` renders formatted m.text correctly pills appear for eve data-testid="avatar-img" data-type="round" style="--cpd-avatar-size: 16px;" - title="" + title="!room1:example.com" > renders formatted m.text correctly pills appear for eve loading="lazy" referrerpolicy="no-referrer" src="mxc://avatar.url/room.png" - title="!room1:example.com" width="16px" /> @@ -166,7 +164,7 @@ exports[` renders formatted m.text correctly pills appear for roo data-testid="avatar-img" data-type="round" style="--cpd-avatar-size: 16px;" - title="" + title="!room1:example.com" > renders formatted m.text correctly pills appear for roo loading="lazy" referrerpolicy="no-referrer" src="mxc://avatar.url/room.png" - title="!room1:example.com" width="16px" /> @@ -278,7 +275,7 @@ exports[` renders formatted m.text correctly pills get injected c data-testid="avatar-img" data-type="round" style="--cpd-avatar-size: 16px;" - title="" + title="@member:domain.bla" > renders formatted m.text correctly pills get injected c loading="lazy" referrerpolicy="no-referrer" src="mxc://avatar.url/image.png" - title="@member:domain.bla" width="16px" /> @@ -313,7 +309,7 @@ exports[` renders plain-text m.text correctly should pillify a pe href="https://matrix.to/#/!room1:example.com/%event_id%" aria-describedby="mx_Pill_0.123456" >Message from Member renders plain-text m.text correctly should pillify a pe href="https://matrix.to/#/!room2:example.com/%event_id%" aria-describedby="mx_Pill_0.123456" >Message in Room 2 renders the room summary 1`] = ` data-type="round" role="presentation" style="--cpd-avatar-size: 54px;" - title="" + title="!room:domain.org" > ! @@ -69,6 +69,13 @@ exports[` renders the room summary 1`] = ` 0 +
with crypto enabled renders 1`] = ` data-type="round" role="button" style="--cpd-avatar-size: 230.39999999999998px;" - title="" + title="@user:example.com" > u diff --git a/test/components/views/rooms/RoomHeader-test.tsx b/test/components/views/rooms/RoomHeader-test.tsx index abd0a93639..0e02733d2a 100644 --- a/test/components/views/rooms/RoomHeader-test.tsx +++ b/test/components/views/rooms/RoomHeader-test.tsx @@ -17,7 +17,7 @@ limitations under the License. import React from "react"; import userEvent from "@testing-library/user-event"; import { CallType, MatrixCall } from "matrix-js-sdk/src/webrtc/call"; -import { EventType, MatrixClient, MatrixEvent, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix"; +import { EventType, JoinRule, MatrixClient, MatrixEvent, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix"; import { getAllByTitle, getByLabelText, getByText, getByTitle, render, screen, waitFor } from "@testing-library/react"; import { mkEvent, stubClient, withClientContextRenderOptions } from "../../../test-utils"; @@ -422,6 +422,26 @@ describe("RoomHeader", () => { }); }); + describe("public room", () => { + it("shows a globe", () => { + const joinRuleEvent = new MatrixEvent({ + type: EventType.RoomJoinRules, + content: { join_rule: JoinRule.Public }, + sender: MatrixClientPeg.get()!.getSafeUserId(), + state_key: "", + room_id: room.roomId, + }); + room.addLiveEvents([joinRuleEvent]); + + const { container } = render( + , + withClientContextRenderOptions(MatrixClientPeg.get()!), + ); + + expect(getByLabelText(container, "Public room")).toBeInTheDocument(); + }); + }); + describe("dm", () => { let client: MatrixClient; beforeEach(() => { diff --git a/test/components/views/rooms/__snapshots__/PinnedEventTile-test.tsx.snap b/test/components/views/rooms/__snapshots__/PinnedEventTile-test.tsx.snap index acba439812..2da4fca0b6 100644 --- a/test/components/views/rooms/__snapshots__/PinnedEventTile-test.tsx.snap +++ b/test/components/views/rooms/__snapshots__/PinnedEventTile-test.tsx.snap @@ -12,7 +12,7 @@ exports[` should render pinned event 1`] = ` data-type="round" role="presentation" style="--cpd-avatar-size: 24px;" - title="" + title="@alice:server.org" > a diff --git a/test/components/views/rooms/__snapshots__/RoomHeader-test.tsx.snap b/test/components/views/rooms/__snapshots__/RoomHeader-test.tsx.snap index bfcc954454..d1ddaeeb42 100644 --- a/test/components/views/rooms/__snapshots__/RoomHeader-test.tsx.snap +++ b/test/components/views/rooms/__snapshots__/RoomHeader-test.tsx.snap @@ -6,28 +6,24 @@ exports[`RoomHeader does not show the face pile for DMs 1`] = ` class="mx_Flex mx_RoomHeader light-panel" style="--mx-flex-display: flex; --mx-flex-direction: row; --mx-flex-align: center; --mx-flex-justify: start; --mx-flex-gap: var(--cpd-space-3x);" > - + ! +