From 4fc054e1c925191d51ba25eb60710e98043d0832 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 4 Jun 2019 16:08:32 -0600 Subject: [PATCH] Add a logged in class to EmbeddedPage and react to MatrixClient changes See https://github.com/vector-im/riot-web/pull/9957 The two hacks introduced here are for different reasons, mostly related to the welcome page. If you land directly on the welcome page, the app's lifecycle is highly unlikely to have a bootstrapped client. This results in the loggedIn class being false. When the client is later set up (loaded from session, new guest account registered, etc) the context fails to update for the EmbeddedPage, and we need to give it a kick to re-render. It's arguable if we should even keep using the context here. --- src/components/structures/EmbeddedPage.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/structures/EmbeddedPage.js b/src/components/structures/EmbeddedPage.js index d10b7f8414..e3c197e1db 100644 --- a/src/components/structures/EmbeddedPage.js +++ b/src/components/structures/EmbeddedPage.js @@ -24,6 +24,8 @@ import request from 'browser-request'; import { _t } from '../../languageHandler'; import sanitizeHtml from 'sanitize-html'; import sdk from '../../index'; +import dis from '../../dispatcher'; +import MatrixClientPeg from '../../MatrixClientPeg'; import { MatrixClient } from 'matrix-js-sdk'; import classnames from 'classnames'; @@ -82,19 +84,31 @@ export default class EmbeddedPage extends React.PureComponent { this.setState({ page: body }); }, ); + + this._dispatcherRef = dis.register(this.onAction); } componentWillUnmount() { this._unmounted = true; + dis.unregister(this._dispatcherRef); } + onAction = (payload) => { + // HACK: Workaround for the context's MatrixClient not being set up at render time. + if (payload.action === 'client_started') { + this.forceUpdate(); + } + }; + render() { - const client = this.context.matrixClient; + // HACK: Workaround for the context's MatrixClient not updating. + const client = this.context.matrixClient || MatrixClientPeg.get(); const isGuest = client ? client.isGuest() : true; const className = this.props.className; const classes = classnames({ [className]: true, [`${className}_guest`]: isGuest, + [`${className}_loggedIn`]: !!client, }); const content =