mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-16 23:45:50 +00:00
Supply Element Call's parameters through a context
Element Call's parameters come from its URL, which works while it owns the page but leaves an embedder with nowhere to put them. Add a context so they can be provided directly, falling back to parsing window.location when no provider is present. This also decouples the thirteen consumers from react-router: useUrlParams called useLocation, so each of them required a router ancestor, which the embedded build will not have. The standalone and widget builds keep their URL-derived behaviour via useUrlParamsFromLocation, provided in App. No functional change.
This commit is contained in:
+32
-14
@@ -31,7 +31,13 @@ import { useTheme } from "./useTheme";
|
||||
import { ProcessorProvider } from "./livekit/TrackProcessorContext";
|
||||
import { type AppViewModel } from "./state/AppViewModel";
|
||||
import { MediaDevicesContext } from "./MediaDevicesContext";
|
||||
import { getUrlParams, HeaderStyle, useUrlParams } from "./UrlParams";
|
||||
import {
|
||||
getUrlParams,
|
||||
HeaderStyle,
|
||||
UrlParamsProvider,
|
||||
useUrlParams,
|
||||
useUrlParamsFromLocation,
|
||||
} from "./UrlParams";
|
||||
import { AppBar } from "./AppBar";
|
||||
import { i18n } from "./utils/i18n";
|
||||
import { useRootElement } from "./RootElementContext";
|
||||
@@ -42,6 +48,16 @@ interface SimpleProviderProps {
|
||||
children: JSX.Element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supplies the URL-derived params to the rest of the app. Only the standalone
|
||||
* and widget builds own the URL, so this lives here in the app shell rather
|
||||
* than alongside the context itself.
|
||||
*/
|
||||
const LocationUrlParamsProvider: FC<SimpleProviderProps> = ({ children }) => {
|
||||
const urlParams = useUrlParamsFromLocation();
|
||||
return <UrlParamsProvider value={urlParams}>{children}</UrlParamsProvider>;
|
||||
};
|
||||
|
||||
const BackgroundProvider: FC<SimpleProviderProps> = ({ children }) => {
|
||||
const { pathname } = useLocation();
|
||||
const { background } = useUrlParams();
|
||||
@@ -102,19 +118,21 @@ export const App: FC<Props> = ({ vm }) => {
|
||||
return (
|
||||
<I18nextProvider i18n={i18n}>
|
||||
<BrowserRouter>
|
||||
<BackgroundProvider>
|
||||
<ThemeProvider>
|
||||
<TooltipProvider>
|
||||
<Suspense fallback={null}>
|
||||
{header === HeaderStyle.AppBar ? (
|
||||
<AppBar>{content}</AppBar>
|
||||
) : (
|
||||
content
|
||||
)}
|
||||
</Suspense>
|
||||
</TooltipProvider>
|
||||
</ThemeProvider>
|
||||
</BackgroundProvider>
|
||||
<LocationUrlParamsProvider>
|
||||
<BackgroundProvider>
|
||||
<ThemeProvider>
|
||||
<TooltipProvider>
|
||||
<Suspense fallback={null}>
|
||||
{header === HeaderStyle.AppBar ? (
|
||||
<AppBar>{content}</AppBar>
|
||||
) : (
|
||||
content
|
||||
)}
|
||||
</Suspense>
|
||||
</TooltipProvider>
|
||||
</ThemeProvider>
|
||||
</BackgroundProvider>
|
||||
</LocationUrlParamsProvider>
|
||||
</BrowserRouter>
|
||||
</I18nextProvider>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user