Skip to content

Commit

Permalink
Add a logged in class to EmbeddedPage and react to MatrixClient changes
Browse files Browse the repository at this point in the history
See element-hq/element-web#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.
  • Loading branch information
turt2live committed Jun 4, 2019
1 parent b412103 commit 4fc054e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/components/structures/EmbeddedPage.js
Expand Up @@ -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';

Expand Down Expand Up @@ -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 = <div className={`${className}_body`}
Expand Down

0 comments on commit 4fc054e

Please sign in to comment.