popovers: Simplify hide_all.

Since we only have tippy popovers now, functions calling
not_hide_tippy_instances have been removed.

Also, all of emoji_picker, stream_popover, user_card etc popovers
are tippy popovers so calling hideAll is enough to hide them all.
This commit is contained in:
Aman Agrawal 2023-09-28 13:24:53 +00:00 committed by Tim Abbott
parent e957603fb9
commit 1d62abee61
12 changed files with 21 additions and 63 deletions

View File

@ -127,7 +127,7 @@ export function build_user_sidebar() {
function do_update_users_for_search() { function do_update_users_for_search() {
// Hide all the popovers but not userlist sidebar // Hide all the popovers but not userlist sidebar
// when the user is searching. // when the user is searching.
popovers.hide_all_except_sidebars(); popovers.hide_all();
build_user_sidebar(); build_user_sidebar();
user_cursor.reset(); user_cursor.reset();
} }

View File

@ -873,21 +873,6 @@ export function initialize() {
return; return;
} }
// Dismiss popovers if the user has clicked outside them
if (
$(
'.popover-inner, #user-profile-modal, .emoji-picker-popover, .app-main [class^="column-"].expanded',
).has(e.target).length === 0
) {
// Since tippy instance can handle outside clicks on their own,
// we don't need to trigger them from here.
// This fixes the bug of `hideAll` being called
// after a tippy popover has been triggered which hides
// the popover without being displayed.
const not_hide_tippy_instances = true;
popovers.hide_all(not_hide_tippy_instances);
}
if (compose_state.composing() && !$(e.target).parents("#compose").length) { if (compose_state.composing() && !$(e.target).parents("#compose").length) {
if ( if (
$(e.target).closest("a").length > 0 || $(e.target).closest("a").length > 0 ||

View File

@ -8,7 +8,6 @@ import * as compose_ui from "./compose_ui";
import {media_breakpoints_num} from "./css_variables"; import {media_breakpoints_num} from "./css_variables";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as popover_menus from "./popover_menus"; import * as popover_menus from "./popover_menus";
import * as popovers from "./popovers";
import * as rows from "./rows"; import * as rows from "./rows";
import * as ui_util from "./ui_util"; import * as ui_util from "./ui_util";
@ -195,7 +194,6 @@ function toggle_giphy_popover(target) {
giphy_popover_instance = instance; giphy_popover_instance = instance;
const $popper = $(giphy_popover_instance.popper).trigger("focus"); const $popper = $(giphy_popover_instance.popper).trigger("focus");
gifs_grid = await renderGIPHYGrid($popper.find(".giphy-content")[0]); gifs_grid = await renderGIPHYGrid($popper.find(".giphy-content")[0]);
popovers.hide_all(true);
const $click_target = $(instance.reference); const $click_target = $(instance.reference);
if ($click_target.parents(".message_edit_form").length === 1) { if ($click_target.parents(".message_edit_form").length === 1) {

View File

@ -242,7 +242,7 @@ function on_show_prep(instance) {
e.stopPropagation(); e.stopPropagation();
instance.hide(); instance.hide();
}); });
popovers.hide_all_except_sidebars(); popovers.hide_all();
} }
function get_props_for_popover_centering(popover_props) { function get_props_for_popover_centering(popover_props) {
@ -584,7 +584,7 @@ export function initialize() {
), ),
); );
popover_instances.compose_control_buttons = instance; popover_instances.compose_control_buttons = instance;
popovers.hide_all_except_sidebars(); popovers.hide_all();
}, },
onHidden(instance) { onHidden(instance) {
instance.destroy(); instance.destroy();
@ -1025,7 +1025,7 @@ export function initialize() {
}); });
}, },
onShow(instance) { onShow(instance) {
popovers.hide_all_except_sidebars(); popovers.hide_all();
const show_unstar_all_button = starred_messages.get_count() > 0; const show_unstar_all_button = starred_messages.get_count() > 0;
instance.setContent( instance.setContent(
@ -1057,7 +1057,7 @@ export function initialize() {
}); });
}, },
onShow(instance) { onShow(instance) {
popovers.hide_all_except_sidebars(); popovers.hide_all();
instance.setContent(parse_html(render_drafts_sidebar_actions({}))); instance.setContent(parse_html(render_drafts_sidebar_actions({})));
}, },
@ -1081,7 +1081,7 @@ export function initialize() {
}); });
}, },
onShow(instance) { onShow(instance) {
popovers.hide_all_except_sidebars(); popovers.hide_all();
instance.setContent(parse_html(render_all_messages_sidebar_actions())); instance.setContent(parse_html(render_all_messages_sidebar_actions()));
}, },
onHidden(instance) { onHidden(instance) {
@ -1098,7 +1098,6 @@ export function initialize() {
$("#compose-textarea").trigger("focus"); $("#compose-textarea").trigger("focus");
}, },
onShow(instance) { onShow(instance) {
popovers.hide_all_except_sidebars(instance);
const formatted_send_later_time = get_formatted_selected_send_later_time(); const formatted_send_later_time = get_formatted_selected_send_later_time();
instance.setContent( instance.setContent(
parse_html( parse_html(

View File

@ -1,4 +1,4 @@
import {hideAll} from "tippy.js"; import * as tippy from "tippy.js";
import * as emoji_picker from "./emoji_picker"; import * as emoji_picker from "./emoji_picker";
import * as playground_links_popover from "./playground_links_popover"; import * as playground_links_popover from "./playground_links_popover";
@ -22,25 +22,7 @@ export function any_active() {
); );
} }
// This function will hide all true popovers (the streamlist and export function hide_all() {
// userlist sidebars use the popover infrastructure, but doesn't work // Hides all tippy instances (tooltips and popovers).
// like a popover structurally). tippy.hideAll();
export function hide_all_except_sidebars(opts) {
if (!opts || !opts.not_hide_tippy_instances) {
// hideAll hides all tippy instances (tooltips and popovers).
hideAll();
}
emoji_picker.hide_emoji_popover();
stream_popover.hide_stream_popover();
user_group_popover.hide();
user_card_popover.hide_all_user_card_popovers();
playground_links_popover.hide();
}
// This function will hide all the popovers, including the mobile web
// or narrow window sidebars.
export function hide_all(not_hide_tippy_instances) {
hide_all_except_sidebars({
not_hide_tippy_instances,
});
} }

View File

@ -104,7 +104,7 @@ function build_stream_popover(opts) {
return; return;
} }
popovers.hide_all_except_sidebars(); popovers.hide_all();
const content = render_stream_sidebar_actions({ const content = render_stream_sidebar_actions({
stream: sub_store.get(stream_id), stream: sub_store.get(stream_id),
}); });

View File

@ -15,7 +15,7 @@ export function is_zoomed_in() {
function zoom_in() { function zoom_in() {
const stream_id = topic_list.active_stream_id(); const stream_id = topic_list.active_stream_id();
popovers.hide_all_except_sidebars(); popovers.hide_all();
pm_list.close(); pm_list.close();
topic_list.zoom_in(); topic_list.zoom_in();
stream_list.zoom_in_topics({ stream_list.zoom_in_topics({
@ -35,7 +35,7 @@ export function zoom_out() {
} }
const $stream_li = topic_list.get_stream_li(); const $stream_li = topic_list.get_stream_li();
popovers.hide_all_except_sidebars(); popovers.hide_all();
topic_list.zoom_out(); topic_list.zoom_out();
stream_list.zoom_out_topics(); stream_list.zoom_out_topics();

View File

@ -26,7 +26,7 @@ import * as overlays from "./overlays";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as popover_menus from "./popover_menus"; import * as popover_menus from "./popover_menus";
import {hide_all, hide_all_except_sidebars} from "./popovers"; import {hide_all} from "./popovers";
import * as rows from "./rows"; import * as rows from "./rows";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as sidebar_ui from "./sidebar_ui"; import * as sidebar_ui from "./sidebar_ui";
@ -597,9 +597,8 @@ function toggle_sidebar_user_card_popover($target) {
// Hiding popovers may mutate current_user_sidebar_user_id. // Hiding popovers may mutate current_user_sidebar_user_id.
const previous_user_sidebar_id = current_user_sidebar_user_id; const previous_user_sidebar_id = current_user_sidebar_user_id;
// Hide popovers, but we don't want to hide the sidebars on // Hide popovers
// smaller browser windows. hide_all();
hide_all_except_sidebars();
if (previous_user_sidebar_id === user_id) { if (previous_user_sidebar_id === user_id) {
// If the popover is already shown, clicking again should toggle it. // If the popover is already shown, clicking again should toggle it.

View File

@ -82,7 +82,7 @@ export function toggle_user_group_info_popover(element, message_id) {
], ],
}, },
onCreate(instance) { onCreate(instance) {
popovers.hide_all_except_sidebars(); popovers.hide_all();
if (message_id) { if (message_id) {
message_lists.current.select_id(message_id); message_lists.current.select_id(message_id);
} }

View File

@ -73,9 +73,8 @@ export class UserSearch {
} }
show_widget() { show_widget() {
// Hide all the popovers but not userlist sidebar // Hide all the popovers.
// when the user wants to search. popovers.hide_all();
popovers.hide_all_except_sidebars();
this.$widget.removeClass("notdisplayed"); this.$widget.removeClass("notdisplayed");
resize.resize_sidebars(); resize.resize_sidebars();
} }

View File

@ -280,7 +280,6 @@ test("handlers", ({override, mock_template}) => {
override(scroll_util, "scroll_element_into_container", () => {}); override(scroll_util, "scroll_element_into_container", () => {});
override(padded_widget, "update_padding", () => {}); override(padded_widget, "update_padding", () => {});
override(popovers, "hide_all", () => {}); override(popovers, "hide_all", () => {});
override(popovers, "hide_all_except_sidebars", () => {});
override(sidebar_ui, "show_userlist_sidebar", () => {}); override(sidebar_ui, "show_userlist_sidebar", () => {});
override(resize, "resize_sidebars", () => {}); override(resize, "resize_sidebars", () => {});

View File

@ -84,7 +84,7 @@ function set_input_val(val) {
test("clear_search", ({override}) => { test("clear_search", ({override}) => {
override(presence, "get_status", () => "active"); override(presence, "get_status", () => "active");
override(presence, "get_user_ids", () => all_user_ids); override(presence, "get_user_ids", () => all_user_ids);
override(popovers, "hide_all_except_sidebars", () => {}); override(popovers, "hide_all", () => {});
override(resize, "resize_sidebars", () => {}); override(resize, "resize_sidebars", () => {});
// Empty because no users match this search string. // Empty because no users match this search string.
@ -108,7 +108,7 @@ test("escape_search", ({override}) => {
page_params.realm_presence_disabled = true; page_params.realm_presence_disabled = true;
override(resize, "resize_sidebars", () => {}); override(resize, "resize_sidebars", () => {});
override(popovers, "hide_all_except_sidebars", () => {}); override(popovers, "hide_all", () => {});
set_input_val("somevalue"); set_input_val("somevalue");
activity.escape_search(); activity.escape_search();
@ -123,7 +123,6 @@ test("escape_search", ({override}) => {
test("blur search right", ({override}) => { test("blur search right", ({override}) => {
override(sidebar_ui, "show_userlist_sidebar", () => {}); override(sidebar_ui, "show_userlist_sidebar", () => {});
override(popovers, "hide_all", () => {}); override(popovers, "hide_all", () => {});
override(popovers, "hide_all_except_sidebars", () => {});
override(resize, "resize_sidebars", () => {}); override(resize, "resize_sidebars", () => {});
$(".user-list-filter").closest = (selector) => { $(".user-list-filter").closest = (selector) => {
@ -140,7 +139,6 @@ test("blur search right", ({override}) => {
test("blur search left", ({override}) => { test("blur search left", ({override}) => {
override(sidebar_ui, "show_streamlist_sidebar", () => {}); override(sidebar_ui, "show_streamlist_sidebar", () => {});
override(popovers, "hide_all", () => {}); override(popovers, "hide_all", () => {});
override(popovers, "hide_all_except_sidebars", () => {});
override(resize, "resize_sidebars", () => {}); override(resize, "resize_sidebars", () => {});
$(".user-list-filter").closest = (selector) => { $(".user-list-filter").closest = (selector) => {
@ -212,7 +210,6 @@ test("click on user header to toggle display", ({override}) => {
const $user_filter = $(".user-list-filter"); const $user_filter = $(".user-list-filter");
override(popovers, "hide_all", () => {}); override(popovers, "hide_all", () => {});
override(popovers, "hide_all_except_sidebars", () => {});
override(sidebar_ui, "show_userlist_sidebar", () => {}); override(sidebar_ui, "show_userlist_sidebar", () => {});
override(resize, "resize_sidebars", () => {}); override(resize, "resize_sidebars", () => {});