Avoid Olm loading loop
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
parent
99b3880afc
commit
cb5f7a3f84
1 changed files with 45 additions and 39 deletions
84
src/App.tsx
84
src/App.tsx
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
import Olm from "@matrix-org/olm";
|
import Olm from "@matrix-org/olm";
|
||||||
import olmWasmPath from "@matrix-org/olm/olm.wasm?url";
|
import olmWasmPath from "@matrix-org/olm/olm.wasm?url";
|
||||||
import React, { Suspense, useState } from "react";
|
import React, { Suspense, useEffect, useState } from "react";
|
||||||
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
|
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
|
||||||
import * as Sentry from "@sentry/react";
|
import * as Sentry from "@sentry/react";
|
||||||
import { OverlayProvider } from "@react-aria/overlays";
|
import { OverlayProvider } from "@react-aria/overlays";
|
||||||
|
@ -39,52 +39,58 @@ interface AppProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function App({ history }: AppProps) {
|
export default function App({ history }: AppProps) {
|
||||||
const [loadingOlm, setLoadingOlm] = useState(false);
|
const [olmLoaded, setOlmLoaded] = useState(false);
|
||||||
|
|
||||||
usePageFocusStyle();
|
usePageFocusStyle();
|
||||||
|
|
||||||
// TODO: https://gitlab.matrix.org/matrix-org/olm/-/issues/10
|
useEffect(() => {
|
||||||
window.OLM_OPTIONS = {};
|
if (!olmLoaded) {
|
||||||
Olm.init({ locateFile: () => olmWasmPath }).then(() => setLoadingOlm(false));
|
// TODO: https://gitlab.matrix.org/matrix-org/olm/-/issues/10
|
||||||
|
window.OLM_OPTIONS = {};
|
||||||
|
Olm.init({ locateFile: () => olmWasmPath }).then(() =>
|
||||||
|
setOlmLoaded(true)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, [olmLoaded, setOlmLoaded]);
|
||||||
|
|
||||||
const errorPage = <CrashView />;
|
const errorPage = <CrashView />;
|
||||||
|
|
||||||
if (loadingOlm) {
|
|
||||||
return <LoadingView />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Router history={history}>
|
<Router history={history}>
|
||||||
<Suspense fallback={null}>
|
{olmLoaded ? (
|
||||||
<ClientProvider>
|
<Suspense fallback={null}>
|
||||||
<InspectorContextProvider>
|
<ClientProvider>
|
||||||
<Sentry.ErrorBoundary fallback={errorPage}>
|
<InspectorContextProvider>
|
||||||
<OverlayProvider>
|
<Sentry.ErrorBoundary fallback={errorPage}>
|
||||||
<Switch>
|
<OverlayProvider>
|
||||||
<SentryRoute exact path="/">
|
<Switch>
|
||||||
<HomePage />
|
<SentryRoute exact path="/">
|
||||||
</SentryRoute>
|
<HomePage />
|
||||||
<SentryRoute exact path="/login">
|
</SentryRoute>
|
||||||
<LoginPage />
|
<SentryRoute exact path="/login">
|
||||||
</SentryRoute>
|
<LoginPage />
|
||||||
<SentryRoute exact path="/register">
|
</SentryRoute>
|
||||||
<RegisterPage />
|
<SentryRoute exact path="/register">
|
||||||
</SentryRoute>
|
<RegisterPage />
|
||||||
<SentryRoute path="/room/:roomId?">
|
</SentryRoute>
|
||||||
<RoomPage />
|
<SentryRoute path="/room/:roomId?">
|
||||||
</SentryRoute>
|
<RoomPage />
|
||||||
<SentryRoute path="/inspector">
|
</SentryRoute>
|
||||||
<SequenceDiagramViewerPage />
|
<SentryRoute path="/inspector">
|
||||||
</SentryRoute>
|
<SequenceDiagramViewerPage />
|
||||||
<SentryRoute path="*">
|
</SentryRoute>
|
||||||
<RoomRedirect />
|
<SentryRoute path="*">
|
||||||
</SentryRoute>
|
<RoomRedirect />
|
||||||
</Switch>
|
</SentryRoute>
|
||||||
</OverlayProvider>
|
</Switch>
|
||||||
</Sentry.ErrorBoundary>
|
</OverlayProvider>
|
||||||
</InspectorContextProvider>
|
</Sentry.ErrorBoundary>
|
||||||
</ClientProvider>
|
</InspectorContextProvider>
|
||||||
</Suspense>
|
</ClientProvider>
|
||||||
|
</Suspense>
|
||||||
|
) : (
|
||||||
|
<LoadingView />
|
||||||
|
)}
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue