mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-04 23:05:50 +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>
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
/*
|
|
Copyright 2026 Element Creations Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
import { type FC, type MouseEvent, type ReactNode, useCallback } from "react";
|
|
import { Link } from "@vector-im/compound-web";
|
|
|
|
import { useLeaveToHome } from "../LeaveToHomeContext";
|
|
|
|
interface Props {
|
|
className?: string;
|
|
children: ReactNode;
|
|
}
|
|
|
|
/**
|
|
* A link out of the call, to wherever the user came from. Renders nothing when
|
|
* there is nowhere to go (see {@link useLeaveToHome}).
|
|
*/
|
|
export const LeaveToHomeLink: FC<Props> = ({ className, children }) => {
|
|
const leaveToHome = useLeaveToHome();
|
|
const onClick = useCallback(
|
|
(e: MouseEvent<HTMLAnchorElement>) => {
|
|
e.preventDefault();
|
|
leaveToHome?.();
|
|
},
|
|
[leaveToHome],
|
|
);
|
|
|
|
if (leaveToHome === null) return null;
|
|
// Where this leads is the shell's business, so the link has no address of
|
|
// its own to offer
|
|
return (
|
|
<Link className={className} href="#" onClick={onClick}>
|
|
{children}
|
|
</Link>
|
|
);
|
|
};
|