mirror of
https://github.com/vector-im/element-call.git
synced 2026-09-22 22:29:30 +00:00
The call reached for react-router in five places to send the user
"home": on leaving without a lobby, from the lobby's recents link, from
the post-call screen, from the error page's return button and from the
header logo. Home is the standalone app's home page; the call has no
idea where that is, and a component has no such place at all — its host
decides what follows a call. Yet the component had to mount a
MemoryRouter just so those hooks would not throw.
`useLeaveToHome` is the way home as the shell supplies it: the app
provides `navigate("/")` from inside its router, the component provides
nothing, and everything that used to link to "/" now either calls it or,
when there is none, offers no way out. The logo becomes a plain logo,
the recents and "not now" links disappear, the error page's button does
too. `ClientProvider`'s logout goes the same way. The component no
longer renders a router.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
112 lines
2.9 KiB
TypeScript
112 lines
2.9 KiB
TypeScript
/*
|
|
Copyright 2025 New Vector Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
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,
|
|
type ReactElement,
|
|
} from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { logger } from "matrix-js-sdk/lib/logger";
|
|
|
|
import { RageshakeButton } from "./settings/RageshakeButton";
|
|
import styles from "./ErrorView.module.css";
|
|
import { useUrlParams } from "./UrlParams";
|
|
import { useLeaveToHome } from "./LeaveToHomeContext";
|
|
import { useHostBridge } from "./HostBridge.ts";
|
|
|
|
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();
|
|
const hostBridge = useHostBridge();
|
|
const leaveToHome = useLeaveToHome();
|
|
|
|
const onReload = useCallback(() => {
|
|
window.location.href = "/";
|
|
}, []);
|
|
|
|
const CloseButton: FC<{ close: () => Promise<void> }> = ({
|
|
close,
|
|
}): ReactElement => {
|
|
// 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);
|
|
});
|
|
};
|
|
return (
|
|
<Button kind="primary" onClick={onClose}>
|
|
{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. Neither applies when there is no home
|
|
// to go to.
|
|
const ReturnToHomeButton = (): ReactElement | null => {
|
|
if (leaveToHome === null) return null;
|
|
return (
|
|
<Button
|
|
kind="tertiary"
|
|
className={styles.homeLink}
|
|
onClick={fatal || location.pathname === "/" ? onReload : leaveToHome}
|
|
>
|
|
{t("return_home_button")}
|
|
</Button>
|
|
);
|
|
};
|
|
|
|
return (
|
|
<div className={styles.error}>
|
|
<BigIcon className={styles.icon}>
|
|
<Icon aria-hidden />
|
|
</BigIcon>
|
|
<Heading as="h1" weight="semibold" size="md">
|
|
{title}
|
|
</Heading>
|
|
{children}
|
|
{rageshake && (
|
|
<RageshakeButton description={`***Error View***: ${title}`} />
|
|
)}
|
|
{hostBridge.close ? (
|
|
<CloseButton close={hostBridge.close} />
|
|
) : (
|
|
!confineToRoom && <ReturnToHomeButton />
|
|
)}
|
|
</div>
|
|
);
|
|
};
|