Files
element-call/src/FullScreenView.tsx
T

123 lines
3.2 KiB
TypeScript
Raw Normal View History

2023-01-03 16:55:26 +00:00
/*
Copyright 2022-2024 New Vector Ltd.
2023-01-03 16:55:26 +00:00
SPDX-License-Identifier: AGPL-3.0-only
Please see LICENSE in the repository root for full details.
2023-01-03 16:55:26 +00:00
*/
2023-09-22 18:05:13 -04:00
import { FC, ReactNode, useCallback, useEffect } from "react";
2021-12-14 18:23:49 -08:00
import { useLocation } from "react-router-dom";
2021-12-14 16:12:58 -08:00
import classNames from "classnames";
2022-10-10 09:19:10 -04:00
import { Trans, useTranslation } from "react-i18next";
2023-07-21 11:58:21 +01:00
import * as Sentry from "@sentry/react";
2023-09-25 18:04:34 +01:00
import { logger } from "matrix-js-sdk/src/logger";
import { Button } from "@vector-im/compound-web";
2022-07-30 09:48:29 +02:00
import { Header, HeaderLogo, LeftNav, RightNav } from "./Header";
import { LinkButton } from "./button";
2022-07-30 09:48:29 +02:00
import styles from "./FullScreenView.module.css";
import { TranslatedError } from "./TranslatedError";
import { Config } from "./config/Config";
import { RageshakeButton } from "./settings/RageshakeButton";
2024-03-13 14:58:21 +01:00
import { useUrlParams } from "./UrlParams";
2021-12-10 16:42:18 -08:00
2022-07-30 09:48:29 +02:00
interface FullScreenViewProps {
className?: string;
children: ReactNode;
}
2023-09-22 18:05:13 -04:00
export const FullScreenView: FC<FullScreenViewProps> = ({
className,
children,
}) => {
2024-03-13 14:58:21 +01:00
const { hideHeader } = useUrlParams();
2021-12-10 16:42:18 -08:00
return (
2021-12-14 16:12:58 -08:00
<div className={classNames(styles.page, className)}>
2021-12-10 16:42:18 -08:00
<Header>
2024-03-13 14:58:21 +01:00
<LeftNav>{!hideHeader && <HeaderLogo />}</LeftNav>
2021-12-10 16:42:18 -08:00
<RightNav />
</Header>
<div className={styles.container}>
<div className={styles.content}>{children}</div>
</div>
</div>
);
2023-09-22 18:05:13 -04:00
};
2021-12-10 16:42:18 -08:00
2022-07-30 09:48:29 +02:00
interface ErrorViewProps {
error: Error;
}
2023-09-22 18:05:13 -04:00
export const ErrorView: FC<ErrorViewProps> = ({ error }) => {
2021-12-10 16:42:18 -08:00
const location = useLocation();
2024-04-23 15:15:13 +02:00
const { confineToRoom } = useUrlParams();
2022-10-10 09:19:10 -04:00
const { t } = useTranslation();
2021-12-10 16:42:18 -08:00
useEffect(() => {
2023-09-25 18:04:34 +01:00
logger.error(error);
2023-07-21 11:58:21 +01:00
Sentry.captureException(error);
2021-12-10 16:42:18 -08:00
}, [error]);
2021-12-14 18:23:49 -08:00
const onReload = useCallback(() => {
2022-07-30 09:48:29 +02:00
window.location.href = "/";
2021-12-14 18:23:49 -08:00
}, []);
2021-12-10 16:42:18 -08:00
return (
<FullScreenView>
2023-11-22 20:07:15 +00:00
<h1>{t("common.error")}</h1>
2022-10-10 09:19:10 -04:00
<p>
{error instanceof TranslatedError
? error.translatedMessage
: error.message}
</p>
<RageshakeButton description={`***Error View***: ${error.message}`} />
2024-04-23 15:15:13 +02:00
{!confineToRoom &&
(location.pathname === "/" ? (
<Button className={styles.homeLink} onClick={onReload}>
2024-04-23 15:15:13 +02:00
{t("return_home_button")}
</Button>
) : (
<LinkButton className={styles.homeLink} to="/">
2024-04-23 15:15:13 +02:00
{t("return_home_button")}
</LinkButton>
))}
2021-12-10 16:42:18 -08:00
</FullScreenView>
);
2023-09-22 18:05:13 -04:00
};
2021-12-10 16:42:18 -08:00
2023-09-22 18:05:13 -04:00
export const CrashView: FC = () => {
2022-10-10 09:19:10 -04:00
const { t } = useTranslation();
2022-07-20 20:43:11 +01:00
const onReload = useCallback(() => {
2022-07-30 09:48:29 +02:00
window.location.href = "/";
2022-07-20 20:43:11 +01:00
}, []);
return (
<FullScreenView>
2023-11-20 13:00:43 +00:00
<Trans i18nKey="full_screen_view_h1">
2022-10-10 09:19:10 -04:00
<h1>Oops, something's gone wrong.</h1>
</Trans>
{Config.get().rageshake?.submit_url && (
2023-11-20 13:00:43 +00:00
<Trans i18nKey="full_screen_view_description">
<p>Submitting debug logs will help us track down the problem.</p>
</Trans>
)}
<RageshakeButton description="***Soft Crash***" />
<Button className={styles.wideButton} onClick={onReload}>
2023-11-20 13:00:43 +00:00
{t("return_home_button")}
2022-07-20 20:43:11 +01:00
</Button>
</FullScreenView>
);
2023-09-22 18:05:13 -04:00
};
2022-07-20 20:43:11 +01:00
2023-09-22 18:05:13 -04:00
export const LoadingView: FC = () => {
2022-10-10 09:19:10 -04:00
const { t } = useTranslation();
2021-12-10 16:42:18 -08:00
return (
<FullScreenView>
<h1>{t("common.loading")}</h1>
2021-12-10 16:42:18 -08:00
</FullScreenView>
);
2023-09-22 18:05:13 -04:00
};