views_util: Extract common calls.

This commit is contained in:
Aman Agrawal 2024-07-21 18:26:58 +00:00 committed by Tim Abbott
parent 2a998e98a6
commit 025fba0a11
3 changed files with 19 additions and 31 deletions

View File

@ -23,12 +23,8 @@ import * as left_sidebar_navigation_area from "./left_sidebar_navigation_area";
import {localstorage} from "./localstorage";
import * as message_store from "./message_store";
import type {Message} from "./message_store";
import * as modals from "./modals";
import * as onboarding_steps from "./onboarding_steps";
import * as overlays from "./overlays";
import * as people from "./people";
import * as popovers from "./popovers";
import * as sidebar_ui from "./sidebar_ui";
import * as stream_color from "./stream_color";
import * as stream_data from "./stream_data";
import * as sub_store from "./sub_store";
@ -1456,18 +1452,7 @@ function move_focus_to_visible_area(): void {
}
export function is_in_focus(): boolean {
// Check if user is focused on
// inbox
return (
is_visible() &&
!compose_state.composing() &&
!popovers.any_active() &&
!sidebar_ui.any_sidebar_expanded_as_overlay() &&
!overlays.any_active() &&
!modals.any_active() &&
!$(".home-page-input").is(":focus") &&
!$("#search_query").is(":focus")
);
return is_visible() && views_util.is_in_focus();
}
export function initialize(): void {

View File

@ -14,7 +14,6 @@ import render_user_with_status_icon from "../templates/user_with_status_icon.hbs
import * as blueslip from "./blueslip";
import * as buddy_data from "./buddy_data";
import * as compose_closed_ui from "./compose_closed_ui";
import * as compose_state from "./compose_state";
import * as dialog_widget from "./dialog_widget";
import * as dropdown_widget from "./dropdown_widget";
import type {DropdownWidget} from "./dropdown_widget";
@ -29,18 +28,14 @@ import type {MessageListData} from "./message_list_data";
import * as message_store from "./message_store";
import type {DisplayRecipientUser, Message} from "./message_store";
import * as message_util from "./message_util";
import * as modals from "./modals";
import * as muted_users from "./muted_users";
import * as onboarding_steps from "./onboarding_steps";
import * as overlays from "./overlays";
import {page_params} from "./page_params";
import * as people from "./people";
import * as popovers from "./popovers";
import * as recent_senders from "./recent_senders";
import * as recent_view_data from "./recent_view_data";
import type {ConversationData} from "./recent_view_data";
import * as recent_view_util from "./recent_view_util";
import * as sidebar_ui from "./sidebar_ui";
import * as stream_data from "./stream_data";
import * as sub_store from "./sub_store";
import * as timerender from "./timerender";
@ -144,16 +139,7 @@ export function save_filters(): void {
export function is_in_focus(): boolean {
// Check if user is focused on Recent Conversations.
return (
recent_view_util.is_visible() &&
!compose_state.composing() &&
!popovers.any_active() &&
!sidebar_ui.any_sidebar_expanded_as_overlay() &&
!overlays.any_active() &&
!modals.any_active() &&
!$(".home-page-input").is(":focus") &&
!$("#search_query").is(":focus")
);
return recent_view_util.is_visible() && views_util.is_in_focus();
}
export function set_default_focus(): void {

View File

@ -4,15 +4,20 @@ import type * as tippy from "tippy.js";
import * as activity_ui from "./activity_ui";
import * as compose_actions from "./compose_actions";
import * as compose_recipient from "./compose_recipient";
import * as compose_state from "./compose_state";
import * as dropdown_widget from "./dropdown_widget";
import {$t} from "./i18n";
import * as message_lists from "./message_lists";
import * as message_view_header from "./message_view_header";
import * as message_viewport from "./message_viewport";
import * as modals from "./modals";
import * as narrow_state from "./narrow_state";
import * as narrow_title from "./narrow_title";
import * as overlays from "./overlays";
import * as pm_list from "./pm_list";
import * as popovers from "./popovers";
import * as resize from "./resize";
import * as sidebar_ui from "./sidebar_ui";
import * as stream_list from "./stream_list";
import * as unread_ui from "./unread_ui";
@ -133,3 +138,15 @@ export function hide(opts: {$view: JQuery; set_visible: (value: boolean) => void
// and not always at the top of the narrow.
message_viewport.plan_scroll_to_selected();
}
export function is_in_focus(): boolean {
return (
!compose_state.composing() &&
!popovers.any_active() &&
!sidebar_ui.any_sidebar_expanded_as_overlay() &&
!overlays.any_active() &&
!modals.any_active() &&
!$(".home-page-input").is(":focus") &&
!$("#search_query").is(":focus")
);
}