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 1 commit
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
14 changes: 14 additions & 0 deletions res/css/structures/_MatrixChat.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,17 @@ limitations under the License.
opacity: 0.8;
}
}

.mx_MatrixChat_wrapper {
display: flex;
flex-flow: column;
height: 100%;
}

.mx_MatrixChat_wrapper_banner {
flex: initial;
}

.mx_MatrixChat_wrapper_content {
flex: auto;
}
13 changes: 13 additions & 0 deletions src/components/structures/MatrixChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { throttle } from "lodash";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import { RoomType } from "matrix-js-sdk/src/@types/event";
import { DecryptionError } from "matrix-js-sdk/src/crypto/algorithms";
import { BannerLifecycle, BannerOpts } from "@matrix-org/react-sdk-module-api/lib/lifecycles/BannerLifecycle";

// focus-visible is a Polyfill for the :focus-visible CSS pseudo-attribute used by various components
import "focus-visible";
Expand Down Expand Up @@ -143,6 +144,7 @@ import { findDMForUser } from "../../utils/dm/findDMForUser";
import { Linkify } from "../../HtmlUtils";
import { NotificationColor } from "../../stores/notifications/NotificationColor";
import { UserTab } from "../views/dialogs/UserTab";
import { ModuleRunner } from "../../modules/ModuleRunner";

// legacy export
export { default as Views } from "../../Views";
Expand Down Expand Up @@ -2135,6 +2137,17 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
return null;
}

const opts: BannerOpts = { banner: undefined };
ModuleRunner.instance.invoke(BannerLifecycle.Banner, opts);
if (opts.banner) {
view = (
<div className="mx_MatrixChat_wrapper">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From an implementation point of view, I don't think we would need to add a wrapper as the banner could be slotted as a sibling of the MatrixChat and the parent section id="matrixchat" is a flex container that applies the same CSS that you declared for mx_MatrixChat_wrapper.
I'd be advocating for a leaner HTML structure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed implementation to place the Banner as a sibling of the mx_MatrixChat. Had to update existing mx_MatrixChat_wrapper with flex-direction: column for the Banner to be shown on the top of Element.

I have created a PR to the module API with a suggestion to add the Banner: matrix-org/matrix-react-sdk-module-api#13

<div className="mx_MatrixChat_wrapper_banner">{opts.banner}</div>
<div className="mx_MatrixChat_wrapper_content">{view}</div>
</div>
);
}

return (
<ErrorBoundary>
<SDKContext.Provider value={this.stores}>{view}</SDKContext.Provider>
Expand Down