mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-10 23:25:52 +00:00
Drop ErrorView's widget prop in favour of the host bridge
ErrorView needed a widget only to decide whether to offer a close button or a link home. That prop was threaded down through ErrorPage, RichError and GroupCallErrorBoundary from seven call sites, to answer the single question of whether the host can dismiss Element Call — which the host bridge now answers directly through the presence of close(). Read the bridge from context in ErrorView and remove the prop, along with the plumbing that carried it. No functional change: the rendered output is unchanged, as the existing snapshot confirms. Move GroupCallView onto the host bridge GroupCallView asked the widget API to keep it on screen, to close it, and to tell it when a preloaded call should join. Route all three through the host bridge and drop the widget prop.
This commit is contained in:
+10
-22
@@ -6,39 +6,27 @@ Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||
import { WidgetApiToWidgetAction } from "matrix-widget-api";
|
||||
import { type IThemeChangeActionRequest } from "matrix-widget-api";
|
||||
|
||||
import { useUrlParams } from "./UrlParams";
|
||||
import { widget } from "./widget";
|
||||
import { useRootElement } from "./RootElementContext";
|
||||
import { useHostBridge } from "./HostBridge";
|
||||
|
||||
export const useTheme = (): void => {
|
||||
const rootElement = useRootElement();
|
||||
const hostBridge = useHostBridge();
|
||||
const { theme } = useUrlParams();
|
||||
const [requestedTheme, setRequestedTheme] = useState(theme);
|
||||
const previousTheme = useRef<string | null>(rootElement.classList.item(0));
|
||||
|
||||
useEffect(() => {
|
||||
if (widget) {
|
||||
const onThemeChange = (
|
||||
ev: CustomEvent<IThemeChangeActionRequest>,
|
||||
): void => {
|
||||
ev.preventDefault();
|
||||
if ("name" in ev.detail.data && typeof ev.detail.data.name === "string")
|
||||
setRequestedTheme(ev.detail.data.name);
|
||||
widget!.api.transport.reply(ev.detail, {});
|
||||
};
|
||||
|
||||
widget.lazyActions.on(WidgetApiToWidgetAction.ThemeChange, onThemeChange);
|
||||
return (): void => {
|
||||
widget!.lazyActions.off(
|
||||
WidgetApiToWidgetAction.ThemeChange,
|
||||
onThemeChange,
|
||||
);
|
||||
};
|
||||
}
|
||||
}, []);
|
||||
const subscription = hostBridge.themeChange$.subscribe(
|
||||
({ data, reply }) => {
|
||||
if (typeof data.name === "string") setRequestedTheme(data.name);
|
||||
reply();
|
||||
},
|
||||
);
|
||||
return (): void => subscription.unsubscribe();
|
||||
}, [hostBridge]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
// If no theme has been explicitly requested we default to dark
|
||||
|
||||
Reference in New Issue
Block a user