overlays: Extract function checking if overlays or modals are open.

This commit is contained in:
Aman Agrawal 2023-10-10 11:56:19 +00:00 committed by Tim Abbott
parent 63c1c9a37a
commit 6713ad9d4d
8 changed files with 15 additions and 13 deletions

View File

@ -35,6 +35,7 @@ import * as narrow from "./narrow";
import * as narrow_state from "./narrow_state";
import * as navigate from "./navigate";
import * as overlays from "./overlays";
import * as overlays_modals from "./overlays_modals";
import {page_params} from "./page_params";
import * as playground_links_popover from "./playground_links_popover";
import * as popover_menus from "./popover_menus";
@ -861,7 +862,7 @@ export function process_hotkey(e, hotkey) {
}
// Prevent navigation in the background when the overlays are active.
if (overlays.is_overlay_or_modal_open()) {
if (overlays_modals.any_active()) {
if (event_name === "view_selected_stream" && overlays.streams_open()) {
stream_settings_ui.view_stream();
return true;

View File

@ -15,7 +15,7 @@ import * as keydown_util from "./keydown_util";
import * as left_sidebar_navigation_area from "./left_sidebar_navigation_area";
import {localstorage} from "./localstorage";
import * as message_store from "./message_store";
import * as overlays from "./overlays";
import * as overlays_modals from "./overlays_modals";
import {page_params} from "./page_params";
import * as people from "./people";
import * as popovers from "./popovers";
@ -1191,7 +1191,7 @@ export function is_in_focus() {
!compose_state.composing() &&
!popovers.any_active() &&
!sidebar_ui.any_sidebar_expanded_as_overlay() &&
!overlays.is_overlay_or_modal_open() &&
!overlays_modals.any_active() &&
!$(".home-page-input").is(":focus")
);
}

View File

@ -61,10 +61,6 @@ export function is_modal_open(): boolean {
return $(".micromodal").hasClass("modal--open");
}
export function is_overlay_or_modal_open(): boolean {
return is_active() || is_modal_open();
}
export function info_overlay_open(): boolean {
return open_overlay_name === "informationalOverlays";
}

View File

@ -0,0 +1,5 @@
import * as overlays from './overlays';
export function any_active(): boolean {
return overlays.is_active() || overlays.is_modal_open();
}

View File

@ -19,7 +19,7 @@ import {localstorage} from "./localstorage";
import * as message_store from "./message_store";
import * as message_util from "./message_util";
import * as muted_users from "./muted_users";
import * as overlays from "./overlays";
import * as overlays_modals from "./overlays_modals";
import {page_params} from "./page_params";
import * as people from "./people";
import * as popovers from "./popovers";
@ -103,7 +103,7 @@ export function is_in_focus() {
!compose_state.composing() &&
!popovers.any_active() &&
!sidebar_ui.any_sidebar_expanded_as_overlay() &&
!overlays.is_overlay_or_modal_open() &&
!overlays_modals.any_active() &&
!$(".home-page-input").is(":focus")
);
}

View File

@ -76,6 +76,7 @@ import * as narrow_title from "./narrow_title";
import * as navbar_alerts from "./navbar_alerts";
import * as navigate from "./navigate";
import * as overlays from "./overlays";
import * as overlays_modals from "./overlays_modals";
import {page_params} from "./page_params";
import * as people from "./people";
import * as playground_links_popover from "./playground_links_popover";
@ -249,7 +250,7 @@ export function initialize_kitchen_sink_stuff() {
message_viewport.$scroll_container.on("wheel", (e) => {
const delta = e.originalEvent.deltaY;
if (!overlays.is_overlay_or_modal_open() && narrow_state.is_message_feed_visible()) {
if (!overlays_modals.any_active() && narrow_state.is_message_feed_visible()) {
// In the message view, we use a throttled mousewheel handler.
throttled_mousewheelhandler(e, delta);
}

View File

@ -14,7 +14,7 @@ import * as message_lists from "./message_lists";
import * as message_store from "./message_store";
import * as message_viewport from "./message_viewport";
import * as narrow_state from "./narrow_state";
import * as overlays from "./overlays";
import * as overlays_modals from "./overlays_modals";
import * as people from "./people";
import * as recent_view_ui from "./recent_view_ui";
import * as ui_report from "./ui_report";
@ -471,7 +471,7 @@ export function mark_pm_as_read(user_ids_string) {
export function viewport_is_visible_and_focused() {
if (
overlays.is_overlay_or_modal_open() ||
overlays_modals.any_active() ||
!is_window_focused() ||
!$("#message_feed_container").is(":visible")
) {

View File

@ -65,7 +65,6 @@ const overlays = mock_esm("../src/overlays", {
info_overlay_open: () => false,
is_modal_open: () => false,
active_modal: () => undefined,
is_overlay_or_modal_open: () => overlays.is_modal_open() || overlays.is_active(),
});
const popovers = mock_esm("../src/user_card_popover", {
manage_menu: {