mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-16 23:45:50 +00:00
Let the shell say where home is, and drop the router from the call
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>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
f5a94ce702
commit
b7285064fd
+41
-11
@@ -5,8 +5,21 @@ 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 JSX, Suspense, useEffect, useState } from "react";
|
||||
import { BrowserRouter, Route, useLocation, Routes } from "react-router-dom";
|
||||
import {
|
||||
type FC,
|
||||
type JSX,
|
||||
Suspense,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useState,
|
||||
} from "react";
|
||||
import {
|
||||
BrowserRouter,
|
||||
Route,
|
||||
useLocation,
|
||||
useNavigate,
|
||||
Routes,
|
||||
} from "react-router-dom";
|
||||
import * as Sentry from "@sentry/react";
|
||||
import { TooltipProvider } from "@vector-im/compound-web";
|
||||
import { logger } from "matrix-js-sdk/lib/logger";
|
||||
@@ -40,6 +53,7 @@ import {
|
||||
nullHostBridge,
|
||||
} from "./HostBridge";
|
||||
import { useInitial } from "./useInitial";
|
||||
import { LeaveToHomeProvider } from "./LeaveToHomeContext";
|
||||
|
||||
const SentryRoute = Sentry.withSentryReactRouterV7Routing(Route);
|
||||
|
||||
@@ -57,6 +71,20 @@ const LocationUrlParamsProvider: FC<SimpleProviderProps> = ({ children }) => {
|
||||
return <UrlParamsProvider value={urlParams}>{children}</UrlParamsProvider>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Supplies the way home. Only the app has one — its home page, with the list
|
||||
* of recent calls — so this, too, lives in the app shell.
|
||||
*/
|
||||
const HomeProvider: FC<SimpleProviderProps> = ({ children }) => {
|
||||
const navigate = useNavigate();
|
||||
const leaveToHome = useCallback(() => {
|
||||
navigate("/")?.catch((e) => logger.error("Failed to navigate home", e));
|
||||
}, [navigate]);
|
||||
return (
|
||||
<LeaveToHomeProvider value={leaveToHome}>{children}</LeaveToHomeProvider>
|
||||
);
|
||||
};
|
||||
|
||||
const BackgroundProvider: FC<SimpleProviderProps> = ({ children }) => {
|
||||
const { pathname } = useLocation();
|
||||
const { background } = useUrlParams();
|
||||
@@ -143,15 +171,17 @@ export const App: FC<Props> = ({ vm, widget }) => {
|
||||
<HostBridgeProvider value={hostBridge}>
|
||||
<BrowserRouter>
|
||||
<LocationUrlParamsProvider>
|
||||
<BackgroundProvider>
|
||||
<ThemeProvider>
|
||||
<TooltipProvider>
|
||||
<Suspense fallback={null}>
|
||||
<MaybeAppBar>{content}</MaybeAppBar>
|
||||
</Suspense>
|
||||
</TooltipProvider>
|
||||
</ThemeProvider>
|
||||
</BackgroundProvider>
|
||||
<HomeProvider>
|
||||
<BackgroundProvider>
|
||||
<ThemeProvider>
|
||||
<TooltipProvider>
|
||||
<Suspense fallback={null}>
|
||||
<MaybeAppBar>{content}</MaybeAppBar>
|
||||
</Suspense>
|
||||
</TooltipProvider>
|
||||
</ThemeProvider>
|
||||
</BackgroundProvider>
|
||||
</HomeProvider>
|
||||
</LocationUrlParamsProvider>
|
||||
</BrowserRouter>
|
||||
</HostBridgeProvider>
|
||||
|
||||
Reference in New Issue
Block a user