2025-01-17 04:35:39 -05:00
|
|
|
/*
|
|
|
|
|
Copyright 2025 New Vector Ltd.
|
|
|
|
|
|
2025-02-18 17:59:58 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
2025-01-17 04:35:39 -05:00
|
|
|
Please see LICENSE in the repository root for full details.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { BigIcon, Button, Heading } from "@vector-im/compound-web";
|
|
|
|
|
import {
|
|
|
|
|
useCallback,
|
|
|
|
|
type ComponentType,
|
|
|
|
|
type FC,
|
|
|
|
|
type ReactNode,
|
|
|
|
|
type SVGAttributes,
|
2025-03-07 10:12:23 +01:00
|
|
|
type ReactElement,
|
2025-01-17 04:35:39 -05:00
|
|
|
} from "react";
|
|
|
|
|
import { useTranslation } from "react-i18next";
|
2025-03-13 13:58:43 +01:00
|
|
|
import { logger } from "matrix-js-sdk/lib/logger";
|
2025-01-17 04:35:39 -05:00
|
|
|
|
|
|
|
|
import { RageshakeButton } from "./settings/RageshakeButton";
|
|
|
|
|
import styles from "./ErrorView.module.css";
|
|
|
|
|
import { useUrlParams } from "./UrlParams";
|
|
|
|
|
import { LinkButton } from "./button";
|
2026-09-02 13:03:23 +02:00
|
|
|
import { useHostBridge } from "./HostBridge.ts";
|
2025-01-17 04:35:39 -05:00
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
Icon: ComponentType<SVGAttributes<SVGElement>>;
|
|
|
|
|
title: string;
|
|
|
|
|
/**
|
|
|
|
|
* Show an option to submit a rageshake.
|
|
|
|
|
* @default false
|
|
|
|
|
*/
|
|
|
|
|
rageshake?: boolean;
|
|
|
|
|
/**
|
|
|
|
|
* Whether the error is considered fatal, i.e. non-recoverable. Causes the app
|
|
|
|
|
* to fully reload when clicking 'return to home'.
|
|
|
|
|
* @default false
|
|
|
|
|
*/
|
|
|
|
|
fatal?: boolean;
|
|
|
|
|
children: ReactNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const ErrorView: FC<Props> = ({
|
|
|
|
|
Icon,
|
|
|
|
|
title,
|
|
|
|
|
rageshake,
|
|
|
|
|
fatal,
|
|
|
|
|
children,
|
|
|
|
|
}) => {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const { confineToRoom } = useUrlParams();
|
2026-09-02 13:03:23 +02:00
|
|
|
const hostBridge = useHostBridge();
|
2025-01-17 04:35:39 -05:00
|
|
|
|
|
|
|
|
const onReload = useCallback(() => {
|
|
|
|
|
window.location.href = "/";
|
|
|
|
|
}, []);
|
|
|
|
|
|
2026-09-02 13:03:23 +02:00
|
|
|
const CloseButton: FC<{ close: () => Promise<void> }> = ({
|
|
|
|
|
close,
|
2025-03-07 10:12:23 +01:00
|
|
|
}): ReactElement => {
|
2026-09-02 13:03:23 +02:00
|
|
|
// When the host can dismiss us, offer that instead of a link home
|
|
|
|
|
const onClose = (): void => {
|
|
|
|
|
close().catch((e) => {
|
|
|
|
|
// What to do here?
|
|
|
|
|
logger.error("Failed to ask the host to close Element Call", e);
|
|
|
|
|
});
|
2025-03-07 10:12:23 +01:00
|
|
|
};
|
|
|
|
|
return (
|
2026-09-02 13:03:23 +02:00
|
|
|
<Button kind="primary" onClick={onClose}>
|
2025-03-07 10:12:23 +01:00
|
|
|
{t("action.close")}
|
|
|
|
|
</Button>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Whether the error is considered fatal or pathname is `/` then reload the all app.
|
|
|
|
|
// If not then navigate to home page.
|
|
|
|
|
const ReturnToHomeButton = (): ReactElement => {
|
|
|
|
|
if (fatal || location.pathname === "/") {
|
|
|
|
|
return (
|
|
|
|
|
<Button kind="tertiary" className={styles.homeLink} onClick={onReload}>
|
|
|
|
|
{t("return_home_button")}
|
|
|
|
|
</Button>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return (
|
|
|
|
|
<LinkButton kind="tertiary" className={styles.homeLink} to="/">
|
|
|
|
|
{t("return_home_button")}
|
|
|
|
|
</LinkButton>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-17 04:35:39 -05:00
|
|
|
return (
|
|
|
|
|
<div className={styles.error}>
|
|
|
|
|
<BigIcon className={styles.icon}>
|
2025-06-16 16:48:13 -04:00
|
|
|
<Icon aria-hidden />
|
2025-01-17 04:35:39 -05:00
|
|
|
</BigIcon>
|
|
|
|
|
<Heading as="h1" weight="semibold" size="md">
|
|
|
|
|
{title}
|
|
|
|
|
</Heading>
|
|
|
|
|
{children}
|
|
|
|
|
{rageshake && (
|
|
|
|
|
<RageshakeButton description={`***Error View***: ${title}`} />
|
|
|
|
|
)}
|
2026-09-02 13:03:23 +02:00
|
|
|
{hostBridge.close ? (
|
|
|
|
|
<CloseButton close={hostBridge.close} />
|
2025-03-07 10:12:23 +01:00
|
|
|
) : (
|
|
|
|
|
!confineToRoom && <ReturnToHomeButton />
|
|
|
|
|
)}
|
2025-01-17 04:35:39 -05:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|