2015-09-17 13:10:01 +02:00
|
|
|
/*
|
2016-01-07 05:06:39 +01:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2020-07-12 22:13:28 +02:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2015-09-17 13:10:01 +02:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-08-05 11:08:30 +02:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2020-07-12 22:13:28 +02:00
|
|
|
import classNames from 'classnames';
|
2021-07-01 23:50:06 +02:00
|
|
|
import { defer } from "matrix-js-sdk/src/utils";
|
2020-07-12 22:13:28 +02:00
|
|
|
|
2017-05-29 18:39:03 +02:00
|
|
|
import Analytics from './Analytics';
|
2020-05-14 04:41:41 +02:00
|
|
|
import dis from './dispatcher/dispatcher';
|
2020-01-24 13:28:03 +01:00
|
|
|
import AsyncWrapper from './AsyncWrapper';
|
2017-01-16 18:01:26 +01:00
|
|
|
|
2016-11-04 15:37:02 +01:00
|
|
|
const DIALOG_CONTAINER_ID = "mx_Dialog_Container";
|
2019-02-28 23:55:58 +01:00
|
|
|
const STATIC_DIALOG_CONTAINER_ID = "mx_Dialog_StaticContainer";
|
2016-11-04 15:37:02 +01:00
|
|
|
|
2020-09-21 22:36:16 +02:00
|
|
|
export interface IModal<T extends any[]> {
|
2020-07-12 22:13:28 +02:00
|
|
|
elem: React.ReactNode;
|
|
|
|
className?: string;
|
|
|
|
beforeClosePromise?: Promise<boolean>;
|
|
|
|
closeReason?: string;
|
|
|
|
onBeforeClose?(reason?: string): Promise<boolean>;
|
|
|
|
onFinished(...args: T): void;
|
|
|
|
close(...args: T): void;
|
2021-03-30 23:37:06 +02:00
|
|
|
hidden?: boolean;
|
2020-07-12 22:13:28 +02:00
|
|
|
}
|
2015-09-17 13:10:01 +02:00
|
|
|
|
2020-09-25 15:08:27 +02:00
|
|
|
export interface IHandle<T extends any[]> {
|
2020-07-12 22:13:28 +02:00
|
|
|
finished: Promise<T>;
|
|
|
|
close(...args: T): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IProps<T extends any[]> {
|
2020-07-13 01:19:15 +02:00
|
|
|
onFinished?(...args: T): void;
|
|
|
|
// TODO improve typing here once all Modals are TS and we can exhaustively check the props
|
|
|
|
[key: string]: any;
|
2020-07-12 22:13:28 +02:00
|
|
|
}
|
2019-03-23 03:22:13 +01:00
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
interface IOptions<T extends any[]> {
|
|
|
|
onBeforeClose?: IModal<T>["onBeforeClose"];
|
|
|
|
}
|
|
|
|
|
|
|
|
type ParametersWithoutFirst<T extends (...args: any) => any> = T extends (a: any, ...args: infer P) => any ? P : never;
|
|
|
|
|
|
|
|
export class ModalManager {
|
|
|
|
private counter = 0;
|
|
|
|
// The modal to prioritise over all others. If this is set, only show
|
|
|
|
// this modal. Remove all other modals from the stack when this modal
|
|
|
|
// is closed.
|
|
|
|
private priorityModal: IModal<any> = null;
|
|
|
|
// The modal to keep open underneath other modals if possible. Useful
|
|
|
|
// for cases like Settings where the modal should remain open while the
|
|
|
|
// user is prompted for more information/errors.
|
|
|
|
private staticModal: IModal<any> = null;
|
|
|
|
// A list of the modals we have stacked up, with the most recent at [0]
|
|
|
|
// Neither the static nor priority modal will be in this list.
|
2020-07-12 22:17:51 +02:00
|
|
|
private modals: IModal<any>[] = [];
|
2020-07-12 22:13:28 +02:00
|
|
|
|
|
|
|
private static getOrCreateContainer() {
|
2016-11-04 15:37:02 +01:00
|
|
|
let container = document.getElementById(DIALOG_CONTAINER_ID);
|
2015-09-17 13:10:01 +02:00
|
|
|
|
|
|
|
if (!container) {
|
|
|
|
container = document.createElement("div");
|
2016-11-04 15:37:02 +01:00
|
|
|
container.id = DIALOG_CONTAINER_ID;
|
2015-09-17 13:10:01 +02:00
|
|
|
document.body.appendChild(container);
|
|
|
|
}
|
|
|
|
|
|
|
|
return container;
|
2016-11-04 15:37:02 +01:00
|
|
|
}
|
2015-09-17 13:10:01 +02:00
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
private static getOrCreateStaticContainer() {
|
2019-02-28 23:55:58 +01:00
|
|
|
let container = document.getElementById(STATIC_DIALOG_CONTAINER_ID);
|
|
|
|
|
|
|
|
if (!container) {
|
|
|
|
container = document.createElement("div");
|
|
|
|
container.id = STATIC_DIALOG_CONTAINER_ID;
|
|
|
|
document.body.appendChild(container);
|
|
|
|
}
|
|
|
|
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2021-03-30 23:37:06 +02:00
|
|
|
public toggleCurrentDialogVisibility() {
|
|
|
|
const modal = this.getCurrentModal();
|
|
|
|
if (!modal) return;
|
|
|
|
modal.hidden = !modal.hidden;
|
|
|
|
}
|
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
public hasDialogs() {
|
|
|
|
return this.priorityModal || this.staticModal || this.modals.length > 0;
|
|
|
|
}
|
|
|
|
|
2020-07-13 01:19:15 +02:00
|
|
|
public createTrackedDialog<T extends any[]>(
|
2020-07-12 22:13:28 +02:00
|
|
|
analyticsAction: string,
|
|
|
|
analyticsInfo: string,
|
|
|
|
...rest: Parameters<ModalManager["createDialog"]>
|
|
|
|
) {
|
2017-07-27 18:19:18 +02:00
|
|
|
Analytics.trackEvent('Modal', analyticsAction, analyticsInfo);
|
2020-07-13 01:19:15 +02:00
|
|
|
return this.createDialog<T>(...rest);
|
2017-07-27 18:19:18 +02:00
|
|
|
}
|
|
|
|
|
2020-07-13 01:19:15 +02:00
|
|
|
public appendTrackedDialog<T extends any[]>(
|
2020-07-12 22:13:28 +02:00
|
|
|
analyticsAction: string,
|
|
|
|
analyticsInfo: string,
|
|
|
|
...rest: Parameters<ModalManager["appendDialog"]>
|
|
|
|
) {
|
2019-06-28 22:34:19 +02:00
|
|
|
Analytics.trackEvent('Modal', analyticsAction, analyticsInfo);
|
2020-07-13 01:19:15 +02:00
|
|
|
return this.appendDialog<T>(...rest);
|
2019-06-28 22:34:19 +02:00
|
|
|
}
|
|
|
|
|
2020-07-13 01:19:15 +02:00
|
|
|
public createDialog<T extends any[]>(
|
2021-07-20 11:33:52 +02:00
|
|
|
Element: React.ComponentType,
|
2020-07-13 01:19:15 +02:00
|
|
|
...rest: ParametersWithoutFirst<ModalManager["createDialogAsync"]>
|
|
|
|
) {
|
|
|
|
return this.createDialogAsync<T>(Promise.resolve(Element), ...rest);
|
2016-11-04 15:37:02 +01:00
|
|
|
}
|
2015-09-17 13:10:01 +02:00
|
|
|
|
2020-07-13 01:19:15 +02:00
|
|
|
public appendDialog<T extends any[]>(
|
2021-07-20 11:33:52 +02:00
|
|
|
Element: React.ComponentType,
|
2020-07-13 01:19:15 +02:00
|
|
|
...rest: ParametersWithoutFirst<ModalManager["appendDialogAsync"]>
|
|
|
|
) {
|
|
|
|
return this.appendDialogAsync<T>(Promise.resolve(Element), ...rest);
|
2019-06-28 22:34:19 +02:00
|
|
|
}
|
|
|
|
|
2020-07-13 01:19:15 +02:00
|
|
|
public createTrackedDialogAsync<T extends any[]>(
|
2020-07-12 22:13:28 +02:00
|
|
|
analyticsAction: string,
|
|
|
|
analyticsInfo: string,
|
2020-10-09 17:59:56 +02:00
|
|
|
...rest: Parameters<ModalManager["createDialogAsync"]>
|
2020-07-12 22:13:28 +02:00
|
|
|
) {
|
2017-08-15 16:52:38 +02:00
|
|
|
Analytics.trackEvent('Modal', analyticsAction, analyticsInfo);
|
2020-07-13 01:19:15 +02:00
|
|
|
return this.createDialogAsync<T>(...rest);
|
2017-07-27 18:19:18 +02:00
|
|
|
}
|
|
|
|
|
2020-07-13 01:19:15 +02:00
|
|
|
public appendTrackedDialogAsync<T extends any[]>(
|
2020-07-12 22:13:28 +02:00
|
|
|
analyticsAction: string,
|
|
|
|
analyticsInfo: string,
|
|
|
|
...rest: Parameters<ModalManager["appendDialogAsync"]>
|
|
|
|
) {
|
2019-06-28 22:34:19 +02:00
|
|
|
Analytics.trackEvent('Modal', analyticsAction, analyticsInfo);
|
2020-07-13 01:19:15 +02:00
|
|
|
return this.appendDialogAsync<T>(...rest);
|
2019-06-28 22:34:19 +02:00
|
|
|
}
|
|
|
|
|
2020-10-13 18:26:48 +02:00
|
|
|
public closeCurrentModal(reason: string) {
|
|
|
|
const modal = this.getCurrentModal();
|
|
|
|
if (!modal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
modal.closeReason = reason;
|
|
|
|
modal.close();
|
|
|
|
}
|
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
private buildModal<T extends any[]>(
|
|
|
|
prom: Promise<React.ComponentType>,
|
|
|
|
props?: IProps<T>,
|
|
|
|
className?: string,
|
2020-08-29 02:11:08 +02:00
|
|
|
options?: IOptions<T>,
|
2020-07-12 22:13:28 +02:00
|
|
|
) {
|
|
|
|
const modal: IModal<T> = {
|
|
|
|
onFinished: props ? props.onFinished : null,
|
|
|
|
onBeforeClose: options.onBeforeClose,
|
|
|
|
beforeClosePromise: null,
|
|
|
|
closeReason: null,
|
|
|
|
className,
|
|
|
|
|
|
|
|
// these will be set below but we need an object reference to pass to getCloseFn before we can do that
|
|
|
|
elem: null,
|
|
|
|
close: null,
|
|
|
|
};
|
2019-06-28 22:34:19 +02:00
|
|
|
|
|
|
|
// never call this from onFinished() otherwise it will loop
|
2020-07-12 22:13:28 +02:00
|
|
|
const [closeDialog, onFinishedProm] = this.getCloseFn<T>(modal, props);
|
2019-06-28 22:34:19 +02:00
|
|
|
|
|
|
|
// don't attempt to reuse the same AsyncWrapper for different dialogs,
|
|
|
|
// otherwise we'll get confused.
|
2020-07-12 22:13:28 +02:00
|
|
|
const modalCount = this.counter++;
|
2019-06-28 22:34:19 +02:00
|
|
|
|
|
|
|
// FIXME: If a dialog uses getDefaultProps it clobbers the onFinished
|
|
|
|
// property set here so you can't close the dialog from a button click!
|
2020-07-12 22:13:28 +02:00
|
|
|
modal.elem = <AsyncWrapper key={modalCount} prom={prom} {...props} onFinished={closeDialog} />;
|
2020-02-06 13:07:13 +01:00
|
|
|
modal.close = closeDialog;
|
2019-06-28 22:34:19 +02:00
|
|
|
|
2021-06-29 14:11:58 +02:00
|
|
|
return { modal, closeDialog, onFinishedProm };
|
2019-06-28 22:34:19 +02:00
|
|
|
}
|
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
private getCloseFn<T extends any[]>(
|
|
|
|
modal: IModal<T>,
|
2020-08-29 02:11:08 +02:00
|
|
|
props: IProps<T>,
|
2020-07-12 22:13:28 +02:00
|
|
|
): [IHandle<T>["close"], IHandle<T>["finished"]] {
|
|
|
|
const deferred = defer<T>();
|
|
|
|
return [async (...args: T) => {
|
2020-02-06 13:10:06 +01:00
|
|
|
if (modal.beforeClosePromise) {
|
|
|
|
await modal.beforeClosePromise;
|
|
|
|
} else if (modal.onBeforeClose) {
|
|
|
|
modal.beforeClosePromise = modal.onBeforeClose(modal.closeReason);
|
|
|
|
const shouldClose = await modal.beforeClosePromise;
|
|
|
|
modal.beforeClosePromise = null;
|
|
|
|
if (!shouldClose) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-08-09 17:47:22 +02:00
|
|
|
deferred.resolve(args);
|
2019-06-28 22:34:19 +02:00
|
|
|
if (props && props.onFinished) props.onFinished.apply(null, args);
|
2020-07-12 22:13:28 +02:00
|
|
|
const i = this.modals.indexOf(modal);
|
2019-06-28 22:34:19 +02:00
|
|
|
if (i >= 0) {
|
2020-07-12 22:13:28 +02:00
|
|
|
this.modals.splice(i, 1);
|
2019-06-28 22:34:19 +02:00
|
|
|
}
|
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
if (this.priorityModal === modal) {
|
|
|
|
this.priorityModal = null;
|
2019-06-28 22:34:19 +02:00
|
|
|
|
|
|
|
// XXX: This is destructive
|
2020-07-12 22:13:28 +02:00
|
|
|
this.modals = [];
|
2019-06-28 22:34:19 +02:00
|
|
|
}
|
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
if (this.staticModal === modal) {
|
|
|
|
this.staticModal = null;
|
2019-06-28 22:34:19 +02:00
|
|
|
|
|
|
|
// XXX: This is destructive
|
2020-07-12 22:13:28 +02:00
|
|
|
this.modals = [];
|
2019-06-28 22:34:19 +02:00
|
|
|
}
|
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
this.reRender();
|
2019-08-09 17:47:22 +02:00
|
|
|
}, deferred.promise];
|
2019-06-28 22:34:19 +02:00
|
|
|
}
|
|
|
|
|
2020-02-06 15:29:35 +01:00
|
|
|
/**
|
|
|
|
* @callback onBeforeClose
|
|
|
|
* @param {string?} reason either "backgroundClick" or null
|
|
|
|
* @return {Promise<bool>} whether the dialog should close
|
|
|
|
*/
|
|
|
|
|
2017-01-16 18:01:26 +01:00
|
|
|
/**
|
|
|
|
* Open a modal view.
|
|
|
|
*
|
|
|
|
* This can be used to display a react component which is loaded as an asynchronous
|
|
|
|
* webpack component. To do this, set 'loader' as:
|
|
|
|
*
|
|
|
|
* (cb) => {
|
|
|
|
* require(['<module>'], cb);
|
|
|
|
* }
|
|
|
|
*
|
2018-11-21 17:56:44 +01:00
|
|
|
* @param {Promise} prom a promise which resolves with a React component
|
|
|
|
* which will be displayed as the modal view.
|
2017-01-16 18:01:26 +01:00
|
|
|
*
|
|
|
|
* @param {Object} props properties to pass to the displayed
|
|
|
|
* component. (We will also pass an 'onFinished' property.)
|
|
|
|
*
|
|
|
|
* @param {String} className CSS class to apply to the modal wrapper
|
2018-05-22 16:47:05 +02:00
|
|
|
*
|
|
|
|
* @param {boolean} isPriorityModal if true, this modal will be displayed regardless
|
|
|
|
* of other modals that are currently in the stack.
|
|
|
|
* Also, when closed, all modals will be removed
|
|
|
|
* from the stack.
|
2019-02-28 23:55:58 +01:00
|
|
|
* @param {boolean} isStaticModal if true, this modal will be displayed under other
|
|
|
|
* modals in the stack. When closed, all modals will
|
|
|
|
* also be removed from the stack. This is not compatible
|
|
|
|
* with being a priority modal. Only one modal can be
|
|
|
|
* static at a time.
|
2020-02-06 15:29:35 +01:00
|
|
|
* @param {Object} options? extra options for the dialog
|
|
|
|
* @param {onBeforeClose} options.onBeforeClose a callback to decide whether to close the dialog
|
2019-04-05 11:18:41 +02:00
|
|
|
* @returns {object} Object with 'close' parameter being a function that will close the dialog
|
2017-01-16 18:01:26 +01:00
|
|
|
*/
|
2020-07-13 01:19:15 +02:00
|
|
|
private createDialogAsync<T extends any[]>(
|
|
|
|
prom: Promise<React.ComponentType>,
|
|
|
|
props?: IProps<T>,
|
2020-07-12 22:13:28 +02:00
|
|
|
className?: string,
|
|
|
|
isPriorityModal = false,
|
|
|
|
isStaticModal = false,
|
2020-08-29 02:11:08 +02:00
|
|
|
options: IOptions<T> = {},
|
2020-07-12 22:13:28 +02:00
|
|
|
): IHandle<T> {
|
2021-06-29 14:11:58 +02:00
|
|
|
const { modal, closeDialog, onFinishedProm } = this.buildModal<T>(prom, props, className, options);
|
2018-05-22 16:47:05 +02:00
|
|
|
if (isPriorityModal) {
|
|
|
|
// XXX: This is destructive
|
2020-07-12 22:13:28 +02:00
|
|
|
this.priorityModal = modal;
|
2019-02-28 23:55:58 +01:00
|
|
|
} else if (isStaticModal) {
|
|
|
|
// This is intentionally destructive
|
2020-07-12 22:13:28 +02:00
|
|
|
this.staticModal = modal;
|
2018-05-22 16:47:05 +02:00
|
|
|
} else {
|
2020-07-12 22:13:28 +02:00
|
|
|
this.modals.unshift(modal);
|
2018-05-22 16:47:05 +02:00
|
|
|
}
|
2016-11-04 15:37:02 +01:00
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
this.reRender();
|
2019-08-09 17:47:22 +02:00
|
|
|
return {
|
|
|
|
close: closeDialog,
|
2019-08-09 18:29:22 +02:00
|
|
|
finished: onFinishedProm,
|
2019-08-09 17:47:22 +02:00
|
|
|
};
|
2016-11-04 15:37:02 +01:00
|
|
|
}
|
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
private appendDialogAsync<T extends any[]>(
|
|
|
|
prom: Promise<React.ComponentType>,
|
|
|
|
props?: IProps<T>,
|
2020-08-29 02:11:08 +02:00
|
|
|
className?: string,
|
2020-07-12 22:13:28 +02:00
|
|
|
): IHandle<T> {
|
2021-06-29 14:11:58 +02:00
|
|
|
const { modal, closeDialog, onFinishedProm } = this.buildModal<T>(prom, props, className, {});
|
2019-06-28 22:34:19 +02:00
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
this.modals.push(modal);
|
|
|
|
this.reRender();
|
2019-08-09 17:47:22 +02:00
|
|
|
return {
|
|
|
|
close: closeDialog,
|
2019-08-09 18:29:22 +02:00
|
|
|
finished: onFinishedProm,
|
2019-08-09 17:47:22 +02:00
|
|
|
};
|
2019-06-28 22:34:19 +02:00
|
|
|
}
|
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
private onBackgroundClick = () => {
|
|
|
|
const modal = this.getCurrentModal();
|
2020-02-06 13:07:13 +01:00
|
|
|
if (!modal) {
|
|
|
|
return;
|
2016-11-04 15:37:02 +01:00
|
|
|
}
|
2020-02-06 13:10:06 +01:00
|
|
|
// we want to pass a reason to the onBeforeClose
|
|
|
|
// callback, but close is currently defined to
|
|
|
|
// pass all number of arguments to the onFinished callback
|
|
|
|
// so, pass the reason to close through a member variable
|
|
|
|
modal.closeReason = "backgroundClick";
|
2020-02-06 13:07:13 +01:00
|
|
|
modal.close();
|
2020-02-06 13:10:06 +01:00
|
|
|
modal.closeReason = null;
|
2020-07-12 22:13:28 +02:00
|
|
|
};
|
2016-11-04 15:37:02 +01:00
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
private getCurrentModal(): IModal<any> {
|
|
|
|
return this.priorityModal ? this.priorityModal : (this.modals[0] || this.staticModal);
|
2016-11-04 15:37:02 +01:00
|
|
|
}
|
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
private reRender() {
|
|
|
|
if (this.modals.length === 0 && !this.priorityModal && !this.staticModal) {
|
2020-08-03 17:02:26 +02:00
|
|
|
// If there is no modal to render, make all of Element available
|
2018-02-08 22:51:07 +01:00
|
|
|
// to screen reader users again
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'aria_unhide_main_app',
|
|
|
|
});
|
2020-07-12 22:13:28 +02:00
|
|
|
ReactDOM.unmountComponentAtNode(ModalManager.getOrCreateContainer());
|
|
|
|
ReactDOM.unmountComponentAtNode(ModalManager.getOrCreateStaticContainer());
|
2016-11-04 15:37:02 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-08 22:51:07 +01:00
|
|
|
// Hide the content outside the modal to screen reader users
|
|
|
|
// so they won't be able to navigate into it and act on it using
|
|
|
|
// screen reader specific features
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'aria_hide_main_app',
|
|
|
|
});
|
2017-12-20 10:09:26 +01:00
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
if (this.staticModal) {
|
|
|
|
const classes = classNames("mx_Dialog_wrapper mx_Dialog_staticWrapper", this.staticModal.className);
|
2019-02-28 23:55:58 +01:00
|
|
|
|
|
|
|
const staticDialog = (
|
|
|
|
<div className={classes}>
|
|
|
|
<div className="mx_Dialog">
|
2020-07-12 22:13:28 +02:00
|
|
|
{ this.staticModal.elem }
|
2019-02-28 23:55:58 +01:00
|
|
|
</div>
|
2020-07-12 22:13:28 +02:00
|
|
|
<div className="mx_Dialog_background mx_Dialog_staticBackground" onClick={this.onBackgroundClick} />
|
2019-02-28 23:55:58 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
ReactDOM.render(staticDialog, ModalManager.getOrCreateStaticContainer());
|
2019-02-28 23:55:58 +01:00
|
|
|
} else {
|
|
|
|
// This is safe to call repeatedly if we happen to do that
|
2020-07-12 22:13:28 +02:00
|
|
|
ReactDOM.unmountComponentAtNode(ModalManager.getOrCreateStaticContainer());
|
2019-02-28 23:55:58 +01:00
|
|
|
}
|
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
const modal = this.getCurrentModal();
|
2021-03-30 23:37:06 +02:00
|
|
|
if (modal !== this.staticModal && !modal.hidden) {
|
2020-07-12 22:13:28 +02:00
|
|
|
const classes = classNames("mx_Dialog_wrapper", modal.className, {
|
|
|
|
mx_Dialog_wrapperWithStaticUnder: this.staticModal,
|
|
|
|
});
|
2019-02-28 23:55:58 +01:00
|
|
|
|
|
|
|
const dialog = (
|
|
|
|
<div className={classes}>
|
|
|
|
<div className="mx_Dialog">
|
2021-07-19 23:43:11 +02:00
|
|
|
{ modal.elem }
|
2019-02-28 23:55:58 +01:00
|
|
|
</div>
|
2020-07-12 22:13:28 +02:00
|
|
|
<div className="mx_Dialog_background" onClick={this.onBackgroundClick} />
|
2017-12-05 08:50:40 +01:00
|
|
|
</div>
|
2019-02-28 23:55:58 +01:00
|
|
|
);
|
2015-09-17 13:10:01 +02:00
|
|
|
|
2021-06-22 10:53:58 +02:00
|
|
|
setImmediate(() => ReactDOM.render(dialog, ModalManager.getOrCreateContainer()));
|
2019-02-28 23:55:58 +01:00
|
|
|
} else {
|
|
|
|
// This is safe to call repeatedly if we happen to do that
|
2020-07-12 22:13:28 +02:00
|
|
|
ReactDOM.unmountComponentAtNode(ModalManager.getOrCreateContainer());
|
2019-02-28 23:55:58 +01:00
|
|
|
}
|
2016-11-04 15:37:02 +01:00
|
|
|
}
|
|
|
|
}
|
2015-09-17 13:10:01 +02:00
|
|
|
|
2020-07-12 22:13:28 +02:00
|
|
|
if (!window.singletonModalManager) {
|
|
|
|
window.singletonModalManager = new ModalManager();
|
2017-06-14 10:31:16 +02:00
|
|
|
}
|
2020-07-12 22:13:28 +02:00
|
|
|
export default window.singletonModalManager;
|