2023-01-03 16:55:26 +00:00
|
|
|
/*
|
2024-09-06 10:22:13 +02:00
|
|
|
Copyright 2022-2024 New Vector Ltd.
|
2023-01-03 16:55:26 +00:00
|
|
|
|
2024-09-06 10:22:13 +02: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
|
|
|
*/
|
|
|
|
|
|
2025-01-17 04:35:39 -05:00
|
|
|
import { type FC, type ReactElement, type ReactNode, useEffect } from "react";
|
2021-12-14 16:12:58 -08:00
|
|
|
import classNames from "classnames";
|
2025-01-17 04:35:39 -05:00
|
|
|
import { 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";
|
2025-01-17 04:35:39 -05:00
|
|
|
import { ErrorIcon } from "@vector-im/compound-design-tokens/assets/web/icons";
|
2022-07-30 09:48:29 +02:00
|
|
|
|
|
|
|
|
import { Header, HeaderLogo, LeftNav, RightNav } from "./Header";
|
|
|
|
|
import styles from "./FullScreenView.module.css";
|
2024-03-13 14:58:21 +01:00
|
|
|
import { useUrlParams } from "./UrlParams";
|
2025-01-17 04:35:39 -05:00
|
|
|
import { RichError } from "./RichError";
|
|
|
|
|
import { ErrorView } from "./ErrorView";
|
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
|
|
|
|
2025-01-17 04:35:39 -05:00
|
|
|
interface ErrorPageProps {
|
|
|
|
|
error: Error | unknown;
|
2022-07-30 09:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-17 04:35:39 -05:00
|
|
|
// Due to this component being used as the crash fallback for Sentry, which has
|
|
|
|
|
// weird type requirements, we can't just give this a type of FC<ErrorPageProps>
|
|
|
|
|
export const ErrorPage = ({ error }: ErrorPageProps): ReactElement => {
|
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]);
|
|
|
|
|
|
2022-07-20 20:43:11 +01:00
|
|
|
return (
|
|
|
|
|
<FullScreenView>
|
2025-01-17 04:35:39 -05:00
|
|
|
{error instanceof RichError ? (
|
|
|
|
|
error.richMessage
|
|
|
|
|
) : (
|
|
|
|
|
<ErrorView Icon={ErrorIcon} title={t("error.generic")} rageshake fatal>
|
|
|
|
|
<p>{t("error.generic_description")}</p>
|
|
|
|
|
</ErrorView>
|
2022-12-22 14:23:19 +00:00
|
|
|
)}
|
2022-07-20 20:43:11 +01:00
|
|
|
</FullScreenView>
|
|
|
|
|
);
|
2023-09-22 18:05:13 -04:00
|
|
|
};
|
2022-07-20 20:43:11 +01:00
|
|
|
|
2025-01-17 04:35:39 -05:00
|
|
|
export const LoadingPage: FC = () => {
|
2022-10-10 09:19:10 -04:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
2021-12-10 16:42:18 -08:00
|
|
|
return (
|
|
|
|
|
<FullScreenView>
|
2023-11-20 11:05:18 +00:00
|
|
|
<h1>{t("common.loading")}</h1>
|
2021-12-10 16:42:18 -08:00
|
|
|
</FullScreenView>
|
|
|
|
|
);
|
2023-09-22 18:05:13 -04:00
|
|
|
};
|