From 9837960ceb79ce9f7545bf0b300e85f18e181506 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 23 Nov 2022 15:35:06 +0000 Subject: [PATCH] Type experiments on Modals To catch https://github.com/matrix-org/matrix-react-sdk/pull/9612 and similar regressions --- src/Modal.tsx | 65 +++++++++++++------- src/components/views/voip/LegacyCallView.tsx | 7 ++- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/Modal.tsx b/src/Modal.tsx index ee24b15d54d..81aea9ae3aa 100644 --- a/src/Modal.tsx +++ b/src/Modal.tsx @@ -23,6 +23,7 @@ import { TypedEventEmitter } from 'matrix-js-sdk/src/models/typed-event-emitter' import dis from './dispatcher/dispatcher'; import AsyncWrapper from './AsyncWrapper'; +import DesktopCapturerSourcePicker from './components/views/elements/DesktopCapturerSourcePicker'; const DIALOG_CONTAINER_ID = "mx_Dialog_Container"; const STATIC_DIALOG_CONTAINER_ID = "mx_Dialog_StaticContainer"; @@ -111,18 +112,18 @@ export class ModalManager extends TypedEventEmitter 0; } - public createDialog( - Element: React.ComponentType, + public createDialog( + Element: T, ...rest: ParametersWithoutFirst ) { - return this.createDialogAsync(Promise.resolve(Element), ...rest); + return this.createDialogAsync(Promise.resolve(Element), ...rest); } - public appendDialog( - Element: React.ComponentType, + public appendDialog( + Element: T, ...rest: ParametersWithoutFirst ) { - return this.appendDialogAsync(Promise.resolve(Element), ...rest); + return this.appendDialogAsync(Promise.resolve(Element), ...rest); } public closeCurrentModal(reason: string) { @@ -134,13 +135,13 @@ export class ModalManager extends TypedEventEmitter( - prom: Promise, - props?: IProps, + private buildModal( + prom: Promise, + props?: IProps, className?: string, - options?: IOptions, + options?: IOptions, ) { - const modal: IModal = { + const modal: IModal = { onFinished: props ? props.onFinished : null, onBeforeClose: options.onBeforeClose, beforeClosePromise: null, @@ -153,7 +154,7 @@ export class ModalManager extends TypedEventEmitter(modal, props); + const [closeDialog, onFinishedProm] = this.getCloseFn(modal, props); // don't attempt to reuse the same AsyncWrapper for different dialogs, // otherwise we'll get confused. @@ -214,6 +215,24 @@ export class ModalManager extends TypedEventEmitter} whether the dialog should close */ + public createDialogAsync( + prom: Promise, + props?: IProps, + className?: string, + isPriorityModal?: boolean, + isStaticModal?: boolean, + options?: IOptions, + ): IHandle; + + public createDialogAsync( + prom: Promise, + props?: IProps, + className?: string, + isPriorityModal?: boolean, + isStaticModal?: boolean, + options?: IOptions, + ): IHandle; + /** * Open a modal view. * @@ -245,16 +264,16 @@ export class ModalManager extends TypedEventEmitter( - prom: Promise, - props?: IProps, + public createDialogAsync( + prom: Promise, + props?: IProps, className?: string, isPriorityModal = false, isStaticModal = false, - options: IOptions = {}, - ): IHandle { + options: IOptions = {}, + ): IHandle { const beforeModal = this.getCurrentModal(); - const { modal, closeDialog, onFinishedProm } = this.buildModal(prom, props, className, options); + const { modal, closeDialog, onFinishedProm } = this.buildModal(prom, props, className, options); if (isPriorityModal) { // XXX: This is destructive this.priorityModal = modal; @@ -274,13 +293,13 @@ export class ModalManager extends TypedEventEmitter( - prom: Promise, - props?: IProps, + private appendDialogAsync( + prom: Promise, + props?: IProps, className?: string, - ): IHandle { + ): IHandle { const beforeModal = this.getCurrentModal(); - const { modal, closeDialog, onFinishedProm } = this.buildModal(prom, props, className, {}); + const { modal, closeDialog, onFinishedProm } = this.buildModal(prom, props, className, {}); this.modals.push(modal); diff --git a/src/components/views/voip/LegacyCallView.tsx b/src/components/views/voip/LegacyCallView.tsx index cabc127ba50..bc8e5c7f6d2 100644 --- a/src/components/views/voip/LegacyCallView.tsx +++ b/src/components/views/voip/LegacyCallView.tsx @@ -297,9 +297,12 @@ export default class LegacyCallView extends React.Component { const [source] = await finished; if (!source) return; - isScreensharing = await this.props.call.setScreensharingEnabled(true, { + // deliberately reintroduce https://github.com/matrix-org/matrix-react-sdk/pull/9612: + // typescript should catch this if we get the modal types working + /*isScreensharing = await this.props.call.setScreensharingEnabled(true, { desktopCapturerSourceId: source, - }); + });*/ + isScreensharing = await this.props.call.setScreensharingEnabled(true, source); } else { isScreensharing = await this.props.call.setScreensharingEnabled(true); }