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

Add banner configurable via module API #10321

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions res/css/structures/_MatrixChat.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ limitations under the License.

.mx_MatrixChat_wrapper {
display: flex;
flex-direction: column;

width: 100%;
height: 100%;
Expand Down
6 changes: 6 additions & 0 deletions src/components/structures/LoggedInView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ISyncStateData, SyncState } from "matrix-js-sdk/src/sync";
import { IUsageLimit } from "matrix-js-sdk/src/@types/partials";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { MatrixError } from "matrix-js-sdk/src/matrix";
import { BannerLifecycle, BannerOpts } from "@matrix-org/react-sdk-module-api/lib/lifecycles/BannerLifecycle";

import { isOnlyCtrlOrCmdKeyEvent, Key } from "../../Keyboard";
import PageTypes from "../../PageTypes";
Expand Down Expand Up @@ -71,6 +72,7 @@ import { UserOnboardingPage } from "../views/user-onboarding/UserOnboardingPage"
import { PipContainer } from "./PipContainer";
import { monitorSyncedPushRules } from "../../utils/pushRules/monitorSyncedPushRules";
import { ConfigOptions } from "../../SdkConfig";
import { ModuleRunner } from "../../modules/ModuleRunner";

// We need to fetch each pinned message individually (if we don't already have it)
// so each pinned message may trigger a request. Limit the number per room for sanity.
Expand Down Expand Up @@ -662,6 +664,9 @@ class LoggedInView extends React.Component<IProps, IState> {
"mx_MatrixChat--with-avatar": this.state.backgroundImage,
});

const bannerOpts: BannerOpts = { banner: undefined };
ModuleRunner.instance.invoke(BannerLifecycle.Banner, bannerOpts);

const audioFeedArraysForCalls = this.state.activeCalls.map((call) => {
return <AudioFeedArrayForLegacyCall call={call} key={call.callId} />;
});
Expand All @@ -675,6 +680,7 @@ class LoggedInView extends React.Component<IProps, IState> {
aria-hidden={this.props.hideToSRUsers}
>
<ToastContainer />
{bannerOpts.banner}
<div className={bodyClasses}>
<div className="mx_LeftPanel_outerWrapper">
<LeftPanelLiveShareWarning isMinimized={this.props.collapseLhs || false} />
Expand Down
20 changes: 19 additions & 1 deletion test/components/structures/LoggedInView-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ limitations under the License.
*/

import React from "react";
import { render, RenderResult } from "@testing-library/react";
import { screen, render, RenderResult } from "@testing-library/react";
import { ConditionKind, EventType, IPushRule, MatrixEvent } from "matrix-js-sdk/src/matrix";
import { ClientEvent } from "matrix-js-sdk/src/client";
import { MediaHandler } from "matrix-js-sdk/src/webrtc/mediaHandler";
import { logger } from "matrix-js-sdk/src/logger";
import { BannerLifecycle, BannerOpts } from "@matrix-org/react-sdk-module-api/lib/lifecycles/BannerLifecycle";

import LoggedInView from "../../../src/components/structures/LoggedInView";
import { SDKContext } from "../../../src/contexts/SDKContext";
import { StandardActions } from "../../../src/notifications/StandardActions";
import ResizeNotifier from "../../../src/utils/ResizeNotifier";
import { flushPromises, getMockClientWithEventEmitter, mockClientMethodsUser } from "../../test-utils";
import { TestSdkContext } from "../../TestSdkContext";
import { ModuleRunner } from "../../../src/modules/ModuleRunner";

describe("<LoggedInView />", () => {
const userId = "@alice:domain.org";
Expand Down Expand Up @@ -323,5 +325,21 @@ describe("<LoggedInView />", () => {
expect(mockClient.setPushRuleActions).not.toHaveBeenCalled();
});
});

it("renders banner via module api", () => {
jest.spyOn(ModuleRunner.instance, "invoke").mockImplementation((lifecycleEvent, opts) => {
if (lifecycleEvent === BannerLifecycle.Banner) {
(opts as BannerOpts).banner = (
<div>
<button>Custom Menu</button>
</div>
);
}
});

getComponent();

expect(screen.getByRole("button", { name: "Custom Menu" })).toBeInTheDocument();
});
});
});