2015-09-17 11:10:01 +00:00
|
|
|
/*
|
2016-01-07 04:06:39 +00:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2020-07-12 20:13:28 +00:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2015-09-17 11:10:01 +00: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 09:08:30 +00:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2020-07-12 20:13:28 +00:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2017-05-29 16:39:03 +00:00
|
|
|
import Analytics from './Analytics';
|
2020-05-14 02:41:41 +00:00
|
|
|
import dis from './dispatcher/dispatcher';
|
2020-01-24 12:28:03 +00:00
|
|
|
import {defer} from './utils/promise';
|
|
|
|
import AsyncWrapper from './AsyncWrapper';
|
2017-01-16 17:01:26 +00:00
|
|
|
|
2016-11-04 14:37:02 +00:00
|
|
|
const DIALOG_CONTAINER_ID = "mx_Dialog_Container";
|
2019-02-28 22:55:58 +00:00
|
|
|
const STATIC_DIALOG_CONTAINER_ID = "mx_Dialog_StaticContainer";
|
2016-11-04 14:37:02 +00:00
|
|
|
|
2020-09-21 20:36:16 +00:00
|
|
|
export interface IModal<T extends any[]> {
|
2020-07-12 20:13:28 +00:00
|
|
|
elem: React.ReactNode;
|
|
|
|
className?: string;
|
|
|
|
beforeClosePromise?: Promise<boolean>;
|
|
|
|
closeReason?: string;
|
|
|
|
onBeforeClose?(reason?: string): Promise<boolean>;
|
|
|
|
onFinished(...args: T): void;
|
|
|
|
close(...args: T): void;
|
|
|
|
}
|
2015-09-17 11:10:01 +00:00
|
|
|
|
2020-09-25 13:08:27 +00:00
|
|
|
export interface IHandle<T extends any[]> {
|
2020-07-12 20:13:28 +00:00
|
|
|
finished: Promise<T>;
|
|
|
|
close(...args: T): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IProps<T extends any[]> {
|
2020-07-12 23:19:15 +00: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 20:13:28 +00:00
|
|
|
}
|
2019-03-23 02:22:13 +00:00
|
|
|
|
2020-07-12 20:13:28 +00: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 20:17:51 +00:00
|
|
|
private modals: IModal<any>[] = [];
|
2020-07-12 20:13:28 +00:00
|
|
|
|
|
|
|
private static getOrCreateContainer() {
|
2016-11-04 14:37:02 +00:00
|
|
|
let container = document.getElementById(DIALOG_CONTAINER_ID);
|
2015-09-17 11:10:01 +00:00
|
|
|
|
|
|
|
if (!container) {
|
|
|
|
container = document.createElement("div");
|
2016-11-04 14:37:02 +00:00
|
|
|
container.id = DIALOG_CONTAINER_ID;
|
2015-09-17 11:10:01 +00:00
|
|
|
document.body.appendChild(container);
|
|
|
|
}
|
|
|
|
|
|
|
|
return container;
|
2016-11-04 14:37:02 +00:00
|
|
|
}
|
2015-09-17 11:10:01 +00:00
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
private static getOrCreateStaticContainer() {
|
2019-02-28 22:55:58 +00: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;
|
|
|
|
}
|
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
public hasDialogs() {
|
|
|
|
return this.priorityModal || this.staticModal || this.modals.length > 0;
|
|
|
|
}
|
|
|
|
|
2020-07-12 23:19:15 +00:00
|
|
|
public createTrackedDialog<T extends any[]>(
|
2020-07-12 20:13:28 +00:00
|
|
|
analyticsAction: string,
|
|
|
|
analyticsInfo: string,
|
|
|
|
...rest: Parameters<ModalManager["createDialog"]>
|
|
|
|
) {
|
2017-07-27 16:19:18 +00:00
|
|
|
Analytics.trackEvent('Modal', analyticsAction, analyticsInfo);
|
2020-07-12 23:19:15 +00:00
|
|
|
return this.createDialog<T>(...rest);
|
2017-07-27 16:19:18 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 23:19:15 +00:00
|
|
|
public appendTrackedDialog<T extends any[]>(
|
2020-07-12 20:13:28 +00:00
|
|
|
analyticsAction: string,
|
|
|
|
analyticsInfo: string,
|
|
|
|
...rest: Parameters<ModalManager["appendDialog"]>
|
|
|
|
) {
|
2019-06-28 20:34:19 +00:00
|
|
|
Analytics.trackEvent('Modal', analyticsAction, analyticsInfo);
|
2020-07-12 23:19:15 +00:00
|
|
|
return this.appendDialog<T>(...rest);
|
2019-06-28 20:34:19 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 23:19:15 +00:00
|
|
|
public createDialog<T extends any[]>(
|
|
|
|
Element: React.ComponentType,
|
|
|
|
...rest: ParametersWithoutFirst<ModalManager["createDialogAsync"]>
|
|
|
|
) {
|
|
|
|
return this.createDialogAsync<T>(Promise.resolve(Element), ...rest);
|
2016-11-04 14:37:02 +00:00
|
|
|
}
|
2015-09-17 11:10:01 +00:00
|
|
|
|
2020-07-12 23:19:15 +00:00
|
|
|
public appendDialog<T extends any[]>(
|
|
|
|
Element: React.ComponentType,
|
|
|
|
...rest: ParametersWithoutFirst<ModalManager["appendDialogAsync"]>
|
|
|
|
) {
|
|
|
|
return this.appendDialogAsync<T>(Promise.resolve(Element), ...rest);
|
2019-06-28 20:34:19 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 23:19:15 +00:00
|
|
|
public createTrackedDialogAsync<T extends any[]>(
|
2020-07-12 20:13:28 +00:00
|
|
|
analyticsAction: string,
|
|
|
|
analyticsInfo: string,
|
2020-10-09 15:59:56 +00:00
|
|
|
...rest: Parameters<ModalManager["createDialogAsync"]>
|
2020-07-12 20:13:28 +00:00
|
|
|
) {
|
2017-08-15 14:52:38 +00:00
|
|
|
Analytics.trackEvent('Modal', analyticsAction, analyticsInfo);
|
2020-07-12 23:19:15 +00:00
|
|
|
return this.createDialogAsync<T>(...rest);
|
2017-07-27 16:19:18 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 23:19:15 +00:00
|
|
|
public appendTrackedDialogAsync<T extends any[]>(
|
2020-07-12 20:13:28 +00:00
|
|
|
analyticsAction: string,
|
|
|
|
analyticsInfo: string,
|
|
|
|
...rest: Parameters<ModalManager["appendDialogAsync"]>
|
|
|
|
) {
|
2019-06-28 20:34:19 +00:00
|
|
|
Analytics.trackEvent('Modal', analyticsAction, analyticsInfo);
|
2020-07-12 23:19:15 +00:00
|
|
|
return this.appendDialogAsync<T>(...rest);
|
2019-06-28 20:34:19 +00:00
|
|
|
}
|
|
|
|
|
2020-10-13 16:26:48 +00:00
|
|
|
public closeCurrentModal(reason: string) {
|
|
|
|
const modal = this.getCurrentModal();
|
|
|
|
if (!modal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
modal.closeReason = reason;
|
|
|
|
modal.close();
|
|
|
|
}
|
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
private buildModal<T extends any[]>(
|
|
|
|
prom: Promise<React.ComponentType>,
|
|
|
|
props?: IProps<T>,
|
|
|
|
className?: string,
|
2020-08-29 00:11:08 +00:00
|
|
|
options?: IOptions<T>,
|
2020-07-12 20:13:28 +00: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 20:34:19 +00:00
|
|
|
|
|
|
|
// never call this from onFinished() otherwise it will loop
|
2020-07-12 20:13:28 +00:00
|
|
|
const [closeDialog, onFinishedProm] = this.getCloseFn<T>(modal, props);
|
2019-06-28 20:34:19 +00:00
|
|
|
|
|
|
|
// don't attempt to reuse the same AsyncWrapper for different dialogs,
|
|
|
|
// otherwise we'll get confused.
|
2020-07-12 20:13:28 +00:00
|
|
|
const modalCount = this.counter++;
|
2019-06-28 20:34:19 +00: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 20:13:28 +00:00
|
|
|
modal.elem = <AsyncWrapper key={modalCount} prom={prom} {...props} onFinished={closeDialog} />;
|
2020-02-06 12:07:13 +00:00
|
|
|
modal.close = closeDialog;
|
2019-06-28 20:34:19 +00:00
|
|
|
|
2019-08-09 15:47:22 +00:00
|
|
|
return {modal, closeDialog, onFinishedProm};
|
2019-06-28 20:34:19 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
private getCloseFn<T extends any[]>(
|
|
|
|
modal: IModal<T>,
|
2020-08-29 00:11:08 +00:00
|
|
|
props: IProps<T>,
|
2020-07-12 20:13:28 +00:00
|
|
|
): [IHandle<T>["close"], IHandle<T>["finished"]] {
|
|
|
|
const deferred = defer<T>();
|
|
|
|
return [async (...args: T) => {
|
2020-02-06 12:10:06 +00: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 15:47:22 +00:00
|
|
|
deferred.resolve(args);
|
2019-06-28 20:34:19 +00:00
|
|
|
if (props && props.onFinished) props.onFinished.apply(null, args);
|
2020-07-12 20:13:28 +00:00
|
|
|
const i = this.modals.indexOf(modal);
|
2019-06-28 20:34:19 +00:00
|
|
|
if (i >= 0) {
|
2020-07-12 20:13:28 +00:00
|
|
|
this.modals.splice(i, 1);
|
2019-06-28 20:34:19 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
if (this.priorityModal === modal) {
|
|
|
|
this.priorityModal = null;
|
2019-06-28 20:34:19 +00:00
|
|
|
|
|
|
|
// XXX: This is destructive
|
2020-07-12 20:13:28 +00:00
|
|
|
this.modals = [];
|
2019-06-28 20:34:19 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
if (this.staticModal === modal) {
|
|
|
|
this.staticModal = null;
|
2019-06-28 20:34:19 +00:00
|
|
|
|
|
|
|
// XXX: This is destructive
|
2020-07-12 20:13:28 +00:00
|
|
|
this.modals = [];
|
2019-06-28 20:34:19 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
this.reRender();
|
2019-08-09 15:47:22 +00:00
|
|
|
}, deferred.promise];
|
2019-06-28 20:34:19 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 14:29:35 +00:00
|
|
|
/**
|
|
|
|
* @callback onBeforeClose
|
|
|
|
* @param {string?} reason either "backgroundClick" or null
|
|
|
|
* @return {Promise<bool>} whether the dialog should close
|
|
|
|
*/
|
|
|
|
|
2017-01-16 17:01:26 +00: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 16:56:44 +00:00
|
|
|
* @param {Promise} prom a promise which resolves with a React component
|
|
|
|
* which will be displayed as the modal view.
|
2017-01-16 17:01:26 +00: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 14:47:05 +00: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 22:55:58 +00: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 14:29:35 +00: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 09:18:41 +00:00
|
|
|
* @returns {object} Object with 'close' parameter being a function that will close the dialog
|
2017-01-16 17:01:26 +00:00
|
|
|
*/
|
2020-07-12 23:19:15 +00:00
|
|
|
private createDialogAsync<T extends any[]>(
|
|
|
|
prom: Promise<React.ComponentType>,
|
|
|
|
props?: IProps<T>,
|
2020-07-12 20:13:28 +00:00
|
|
|
className?: string,
|
|
|
|
isPriorityModal = false,
|
|
|
|
isStaticModal = false,
|
2020-08-29 00:11:08 +00:00
|
|
|
options: IOptions<T> = {},
|
2020-07-12 20:13:28 +00:00
|
|
|
): IHandle<T> {
|
|
|
|
const {modal, closeDialog, onFinishedProm} = this.buildModal<T>(prom, props, className, options);
|
2018-05-22 14:47:05 +00:00
|
|
|
if (isPriorityModal) {
|
|
|
|
// XXX: This is destructive
|
2020-07-12 20:13:28 +00:00
|
|
|
this.priorityModal = modal;
|
2019-02-28 22:55:58 +00:00
|
|
|
} else if (isStaticModal) {
|
|
|
|
// This is intentionally destructive
|
2020-07-12 20:13:28 +00:00
|
|
|
this.staticModal = modal;
|
2018-05-22 14:47:05 +00:00
|
|
|
} else {
|
2020-07-12 20:13:28 +00:00
|
|
|
this.modals.unshift(modal);
|
2018-05-22 14:47:05 +00:00
|
|
|
}
|
2016-11-04 14:37:02 +00:00
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
this.reRender();
|
2019-08-09 15:47:22 +00:00
|
|
|
return {
|
|
|
|
close: closeDialog,
|
2019-08-09 16:29:22 +00:00
|
|
|
finished: onFinishedProm,
|
2019-08-09 15:47:22 +00:00
|
|
|
};
|
2016-11-04 14:37:02 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
private appendDialogAsync<T extends any[]>(
|
|
|
|
prom: Promise<React.ComponentType>,
|
|
|
|
props?: IProps<T>,
|
2020-08-29 00:11:08 +00:00
|
|
|
className?: string,
|
2020-07-12 20:13:28 +00:00
|
|
|
): IHandle<T> {
|
|
|
|
const {modal, closeDialog, onFinishedProm} = this.buildModal<T>(prom, props, className, {});
|
2019-06-28 20:34:19 +00:00
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
this.modals.push(modal);
|
|
|
|
this.reRender();
|
2019-08-09 15:47:22 +00:00
|
|
|
return {
|
|
|
|
close: closeDialog,
|
2019-08-09 16:29:22 +00:00
|
|
|
finished: onFinishedProm,
|
2019-08-09 15:47:22 +00:00
|
|
|
};
|
2019-06-28 20:34:19 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
private onBackgroundClick = () => {
|
|
|
|
const modal = this.getCurrentModal();
|
2020-02-06 12:07:13 +00:00
|
|
|
if (!modal) {
|
|
|
|
return;
|
2016-11-04 14:37:02 +00:00
|
|
|
}
|
2020-02-06 12:10:06 +00: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 12:07:13 +00:00
|
|
|
modal.close();
|
2020-02-06 12:10:06 +00:00
|
|
|
modal.closeReason = null;
|
2020-07-12 20:13:28 +00:00
|
|
|
};
|
2016-11-04 14:37:02 +00:00
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
private getCurrentModal(): IModal<any> {
|
|
|
|
return this.priorityModal ? this.priorityModal : (this.modals[0] || this.staticModal);
|
2016-11-04 14:37:02 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
private reRender() {
|
|
|
|
if (this.modals.length === 0 && !this.priorityModal && !this.staticModal) {
|
2020-08-03 15:02:26 +00:00
|
|
|
// If there is no modal to render, make all of Element available
|
2018-02-08 21:51:07 +00:00
|
|
|
// to screen reader users again
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'aria_unhide_main_app',
|
|
|
|
});
|
2020-07-12 20:13:28 +00:00
|
|
|
ReactDOM.unmountComponentAtNode(ModalManager.getOrCreateContainer());
|
|
|
|
ReactDOM.unmountComponentAtNode(ModalManager.getOrCreateStaticContainer());
|
2016-11-04 14:37:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-08 21:51:07 +00: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 09:09:26 +00:00
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
if (this.staticModal) {
|
|
|
|
const classes = classNames("mx_Dialog_wrapper mx_Dialog_staticWrapper", this.staticModal.className);
|
2019-02-28 22:55:58 +00:00
|
|
|
|
|
|
|
const staticDialog = (
|
|
|
|
<div className={classes}>
|
|
|
|
<div className="mx_Dialog">
|
2020-07-12 20:13:28 +00:00
|
|
|
{ this.staticModal.elem }
|
2019-02-28 22:55:58 +00:00
|
|
|
</div>
|
2020-07-12 20:13:28 +00:00
|
|
|
<div className="mx_Dialog_background mx_Dialog_staticBackground" onClick={this.onBackgroundClick} />
|
2019-02-28 22:55:58 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
ReactDOM.render(staticDialog, ModalManager.getOrCreateStaticContainer());
|
2019-02-28 22:55:58 +00:00
|
|
|
} else {
|
|
|
|
// This is safe to call repeatedly if we happen to do that
|
2020-07-12 20:13:28 +00:00
|
|
|
ReactDOM.unmountComponentAtNode(ModalManager.getOrCreateStaticContainer());
|
2019-02-28 22:55:58 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
const modal = this.getCurrentModal();
|
|
|
|
if (modal !== this.staticModal) {
|
|
|
|
const classes = classNames("mx_Dialog_wrapper", modal.className, {
|
|
|
|
mx_Dialog_wrapperWithStaticUnder: this.staticModal,
|
|
|
|
});
|
2019-02-28 22:55:58 +00:00
|
|
|
|
|
|
|
const dialog = (
|
|
|
|
<div className={classes}>
|
|
|
|
<div className="mx_Dialog">
|
|
|
|
{modal.elem}
|
|
|
|
</div>
|
2020-07-12 20:13:28 +00:00
|
|
|
<div className="mx_Dialog_background" onClick={this.onBackgroundClick} />
|
2017-12-05 07:50:40 +00:00
|
|
|
</div>
|
2019-02-28 22:55:58 +00:00
|
|
|
);
|
2015-09-17 11:10:01 +00:00
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
ReactDOM.render(dialog, ModalManager.getOrCreateContainer());
|
2019-02-28 22:55:58 +00:00
|
|
|
} else {
|
|
|
|
// This is safe to call repeatedly if we happen to do that
|
2020-07-12 20:13:28 +00:00
|
|
|
ReactDOM.unmountComponentAtNode(ModalManager.getOrCreateContainer());
|
2019-02-28 22:55:58 +00:00
|
|
|
}
|
2016-11-04 14:37:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-17 11:10:01 +00:00
|
|
|
|
2020-07-12 20:13:28 +00:00
|
|
|
if (!window.singletonModalManager) {
|
|
|
|
window.singletonModalManager = new ModalManager();
|
2017-06-14 08:31:16 +00:00
|
|
|
}
|
2020-07-12 20:13:28 +00:00
|
|
|
export default window.singletonModalManager;
|