element-call/src/App.jsx

106 lines
2.8 KiB
React
Raw Normal View History

2021-07-16 21:38:44 +00:00
/*
Copyright 2021 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2021-12-10 21:27:27 +00:00
import React, { useEffect, useState } from "react";
import {
BrowserRouter as Router,
Switch,
Route,
useLocation,
useHistory,
} from "react-router-dom";
2021-10-06 18:38:26 +00:00
import * as Sentry from "@sentry/react";
2021-12-09 20:58:30 +00:00
import { OverlayProvider } from "@react-aria/overlays";
2021-08-20 00:49:45 +00:00
import { Home } from "./Home";
2021-08-20 23:23:12 +00:00
import { LoginPage } from "./LoginPage";
2021-12-09 20:58:30 +00:00
import { RegisterPage } from "./RegisterPage";
import { Room } from "./Room";
2021-12-18 00:30:10 +00:00
import {
ClientProvider,
defaultHomeserverHost,
} from "./ConferenceCallManagerHooks";
2021-12-10 21:06:16 +00:00
import { useFocusVisible } from "@react-aria/interactions";
import styles from "./App.module.css";
2021-12-18 00:30:10 +00:00
import { LoadingView } from "./FullScreenView";
2021-07-16 21:22:03 +00:00
2021-10-06 18:38:26 +00:00
const SentryRoute = Sentry.withSentryRouting(Route);
2021-12-18 00:30:10 +00:00
export default function App({ history }) {
2021-12-10 21:06:16 +00:00
const { isFocusVisible } = useFocusVisible();
useEffect(() => {
const classList = document.body.classList;
const hasClass = classList.contains(styles.hideFocus);
if (isFocusVisible && hasClass) {
classList.remove(styles.hideFocus);
} else if (!isFocusVisible && !hasClass) {
classList.add(styles.hideFocus);
}
return () => {
classList.remove(styles.hideFocus);
};
}, [isFocusVisible]);
2021-07-16 21:22:03 +00:00
return (
2021-12-18 00:30:10 +00:00
<Router history={history}>
<ClientProvider>
2021-12-09 20:58:30 +00:00
<OverlayProvider>
2021-12-04 00:42:29 +00:00
<Switch>
2021-12-09 20:58:30 +00:00
<SentryRoute exact path="/">
<Home />
</SentryRoute>
2021-12-04 00:42:29 +00:00
<SentryRoute exact path="/login">
2021-12-09 20:58:30 +00:00
<LoginPage />
2021-12-04 00:42:29 +00:00
</SentryRoute>
<SentryRoute exact path="/register">
2021-12-09 20:58:30 +00:00
<RegisterPage />
2021-12-04 00:42:29 +00:00
</SentryRoute>
<SentryRoute path="/room/:roomId?">
2021-12-09 20:58:30 +00:00
<Room />
2021-12-04 00:42:29 +00:00
</SentryRoute>
2021-12-10 21:27:27 +00:00
<SentryRoute path="*">
<RoomRedirect />
</SentryRoute>
2021-12-04 00:42:29 +00:00
</Switch>
2021-12-09 20:58:30 +00:00
</OverlayProvider>
</ClientProvider>
2021-12-04 00:42:29 +00:00
</Router>
2021-07-16 21:22:03 +00:00
);
}
2021-12-10 21:27:27 +00:00
function RoomRedirect() {
const { pathname } = useLocation();
const history = useHistory();
useEffect(() => {
2021-12-18 00:30:10 +00:00
let roomId = pathname;
2021-12-10 21:27:27 +00:00
2021-12-18 00:30:10 +00:00
if (pathname.startsWith("/")) {
roomId = roomId.substr(1, roomId.length);
2021-12-10 21:27:27 +00:00
}
2021-12-18 00:30:10 +00:00
if (!roomId.startsWith("#") && !roomId.startsWith("!")) {
roomId = `#${roomId}:${defaultHomeserverHost}`;
}
2021-12-10 21:27:27 +00:00
2021-12-18 00:30:10 +00:00
history.replace(`/room/${roomId}`);
}, [pathname, history]);
2021-12-10 21:27:27 +00:00
2021-12-11 00:42:18 +00:00
return <LoadingView />;
2021-12-10 21:27:27 +00:00
}