Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

overlays: Allow calling open_modal with a modal already open.

Tim Abbott828867c7331d
diff --git a/static/js/dialog_widget.js b/static/js/dialog_widget.js
index 85d153138e3..c7a34dc7abe 100644
--- a/static/js/dialog_widget.js
+++ b/static/js/dialog_widget.js
@@ -95,12 +95,6 @@ export function launch(conf) {
}
}
- // Close any existing modals--on settings screens you can
- // have multiple buttons that need confirmation.
- if (overlays.is_modal_open()) {
- close_modal();
- }
-
const html_submit_button = conf.html_submit_button || $t_html({defaultMessage: "Save changes"});
const html = render_dialog_widget({
heading_text: conf.html_heading,
diff --git a/static/js/overlays.js b/static/js/overlays.js
index d8b832644f7..b6ffad32ca7 100644
--- a/static/js/overlays.js
+++ b/static/js/overlays.js
@@ -121,7 +121,31 @@ export function open_modal(selector, conf = {}) {
}
if (is_modal_open()) {
- blueslip.error("open_modal() was called while " + active_modal() + " modal was open.");
+ /*
+ Our modal system doesn't directly support opening a modal
+ when one is already open, because the `is_modal_open` CSS
+ class doesn't update until Micromodal has finished its
+ animations, which can take 100ms or more.
+
+ We can likely fix that, but in the meantime, we should
+ handle this situation correctly, by closing the current
+ modal, waiting for it to finish closing, and then attempting
+ to open the current modal again.
+ */
+ if (!conf.recursive_call_count) {
+ conf.recursive_call_count = 1;
+ } else {
+ conf.recursive_call_count += 1;
+ }
+ if (conf.recursive_call_count > 50) {
+ blueslip.error("Modal incorrectly is still open: " + selector);
+ return;
+ }
+
+ close_active_modal();
+ setTimeout(() => {
+ open_modal(selector, conf);
+ }, 10);
return;
}