mirror of https://github.com/vector-im/riot-web
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?pull/21833/head
parent
a0c2a39dc7
commit
7e07a42dc1
39
src/Modal.js
39
src/Modal.js
|
@ -47,7 +47,7 @@ class ModalManager {
|
||||||
} */
|
} */
|
||||||
];
|
];
|
||||||
|
|
||||||
this.closeAll = this.closeAll.bind(this);
|
this.onBackgroundClick = this.onBackgroundClick.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
hasDialogs() {
|
hasDialogs() {
|
||||||
|
@ -124,6 +124,7 @@ class ModalManager {
|
||||||
);
|
);
|
||||||
modal.onFinished = props ? props.onFinished : null;
|
modal.onFinished = props ? props.onFinished : null;
|
||||||
modal.className = className;
|
modal.className = className;
|
||||||
|
modal.close = closeDialog;
|
||||||
|
|
||||||
return {modal, closeDialog, onFinishedProm};
|
return {modal, closeDialog, onFinishedProm};
|
||||||
}
|
}
|
||||||
|
@ -216,28 +217,16 @@ class ModalManager {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
closeAll() {
|
onBackgroundClick() {
|
||||||
const modalsToClose = this._modals.slice();
|
const modal = this._getCurrentModal();
|
||||||
this._modals = [];
|
if (!modal) {
|
||||||
|
return;
|
||||||
if (this._priorityModal) {
|
|
||||||
modalsToClose.push(this._priorityModal);
|
|
||||||
this._priorityModal = null;
|
|
||||||
}
|
}
|
||||||
|
modal.close();
|
||||||
|
}
|
||||||
|
|
||||||
if (this._staticModal && modalsToClose.length === 0) {
|
_getCurrentModal() {
|
||||||
modalsToClose.push(this._staticModal);
|
return this._priorityModal ? this._priorityModal : (this._modals[0] || 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_reRender() {
|
_reRender() {
|
||||||
|
@ -268,7 +257,7 @@ class ModalManager {
|
||||||
<div className="mx_Dialog">
|
<div className="mx_Dialog">
|
||||||
{ this._staticModal.elem }
|
{ this._staticModal.elem }
|
||||||
</div>
|
</div>
|
||||||
<div className="mx_Dialog_background mx_Dialog_staticBackground" onClick={this.closeAll}></div>
|
<div className="mx_Dialog_background mx_Dialog_staticBackground" onClick={this.onBackgroundClick}></div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -278,8 +267,8 @@ class ModalManager {
|
||||||
ReactDOM.unmountComponentAtNode(this.getOrCreateStaticContainer());
|
ReactDOM.unmountComponentAtNode(this.getOrCreateStaticContainer());
|
||||||
}
|
}
|
||||||
|
|
||||||
const modal = this._priorityModal ? this._priorityModal : this._modals[0];
|
const modal = this._getCurrentModal();
|
||||||
if (modal) {
|
if (modal !== this._staticModal) {
|
||||||
const classes = "mx_Dialog_wrapper "
|
const classes = "mx_Dialog_wrapper "
|
||||||
+ (this._staticModal ? "mx_Dialog_wrapperWithStaticUnder " : '')
|
+ (this._staticModal ? "mx_Dialog_wrapperWithStaticUnder " : '')
|
||||||
+ (modal.className ? modal.className : '');
|
+ (modal.className ? modal.className : '');
|
||||||
|
@ -289,7 +278,7 @@ class ModalManager {
|
||||||
<div className="mx_Dialog">
|
<div className="mx_Dialog">
|
||||||
{modal.elem}
|
{modal.elem}
|
||||||
</div>
|
</div>
|
||||||
<div className="mx_Dialog_background" onClick={this.closeAll}></div>
|
<div className="mx_Dialog_background" onClick={this.onBackgroundClick}></div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue