commit 6daaef42afe19319fe599a1e30f9723b57d29075
parent a1e4ebb58a0247268b91ce3a2e6cd71f7c61bc9f
Author: MTRNord <mtrnord1@gmail.com>
Date: Fri, 11 Feb 2022 19:37:07 +0100
Make sure we wait for client to exist before rendering the rest of the page
Diffstat:
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/pages/_app.tsx b/pages/_app.tsx
@@ -5,7 +5,7 @@ import { ClientContext, } from '../components/ClientContext';
import React, { PureComponent } from 'react';
import Head from 'next/head';
import { ToastContainer } from 'react-toastify';
-import { appWithTranslation } from 'next-i18next';
+import { appWithTranslation, i18n } from 'next-i18next';
import Footer from '../components/Footer';
import dynamic from 'next/dynamic';
import MatrixClient from "../helpers/matrix_client";
@@ -41,6 +41,13 @@ class MyApp extends PureComponent<AppProps, State> {
render() {
const Component = this.props.Component;
+ if (!this.state.client || !this.state.guest_client) {
+ return (
+ <div className="m-0 w-full">
+ <div className="loader">{i18n?.t("Loading")}...</div>
+ </div>
+ );
+ }
return (
<>
<Head>
diff --git a/pages/profile/[userid].tsx b/pages/profile/[userid].tsx
@@ -58,9 +58,10 @@ class Profile extends PureComponent<Props, State> {
}
async componentDidMount() {
+ console.log(`client: ${this.context.client}`);
// auto-register as a guest if not logged in
if (!this.context.client?.accessToken) {
- this.registerAsGuest();
+ await this.registerAsGuest();
} else {
console.log("Already logged in");
}
@@ -80,7 +81,7 @@ class Profile extends PureComponent<Props, State> {
try {
const profile = await this.context.client?.getProfile(this.props.mxid);
this.setState({
- displayname: profile?.displayname ?? this.props.event.sender,
+ displayname: profile?.displayname ?? this.props.mxid,
avatar_url: profile?.avatar_url,
});
} catch (error) {