From 7e07a42dc14594e640598ae4613e87e61b9e3155 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 6 Feb 2020 13:07:13 +0100 Subject: [PATCH] resolve finished promise when closing dialog by clicking background ... by calling the same close method as otherwise and not have a special path that just calls the onFinished callback. This will also not close all the dialogs anymore, but that sort of seems like the intented behaviour? --- src/Modal.js | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/Modal.js b/src/Modal.js index 54e56edd72..33c3140ff1 100644 --- a/src/Modal.js +++ b/src/Modal.js @@ -47,7 +47,7 @@ class ModalManager { } */ ]; - this.closeAll = this.closeAll.bind(this); + this.onBackgroundClick = this.onBackgroundClick.bind(this); } hasDialogs() { @@ -124,6 +124,7 @@ class ModalManager { ); modal.onFinished = props ? props.onFinished : null; modal.className = className; + modal.close = closeDialog; return {modal, closeDialog, onFinishedProm}; } @@ -216,28 +217,16 @@ class ModalManager { }; } - closeAll() { - const modalsToClose = this._modals.slice(); - this._modals = []; - - if (this._priorityModal) { - modalsToClose.push(this._priorityModal); - this._priorityModal = null; + onBackgroundClick() { + const modal = this._getCurrentModal(); + if (!modal) { + return; } + modal.close(); + } - if (this._staticModal && modalsToClose.length === 0) { - modalsToClose.push(this._staticModal); - this._staticModal = null; - } - - for (let i = 0; i < modalsToClose.length; i++) { - const m = modalsToClose[i]; - if (m && m.onFinished) { - m.onFinished(false); - } - } - - this._reRender(); + _getCurrentModal() { + return this._priorityModal ? this._priorityModal : (this._modals[0] || this._staticModal); } _reRender() { @@ -268,7 +257,7 @@ class ModalManager {
{ this._staticModal.elem }
-
+
); @@ -278,8 +267,8 @@ class ModalManager { ReactDOM.unmountComponentAtNode(this.getOrCreateStaticContainer()); } - const modal = this._priorityModal ? this._priorityModal : this._modals[0]; - if (modal) { + const modal = this._getCurrentModal(); + if (modal !== this._staticModal) { const classes = "mx_Dialog_wrapper " + (this._staticModal ? "mx_Dialog_wrapperWithStaticUnder " : '') + (modal.className ? modal.className : ''); @@ -289,7 +278,7 @@ class ModalManager {
{modal.elem}
-
+
);