popovers: Simplify sidebar hiding logic for user menus.

Structurally, the goal of this logic is to just hide all popovers
(including potential user popovers) and not the sidebars; use the
function designed for that purpose rather than hackily
hand-implementing it.
This commit is contained in:
Tim Abbott 2022-11-09 16:18:42 -08:00
parent 87bc18c2be
commit 56005da39d
1 changed files with 7 additions and 13 deletions

View File

@ -1193,24 +1193,18 @@ export function register_click_handlers() {
$("#user_presences").on("click", ".user-list-sidebar-menu-icon", function (e) { $("#user_presences").on("click", ".user-list-sidebar-menu-icon", function (e) {
e.stopPropagation(); e.stopPropagation();
// use email of currently selected user, rather than some elem comparison,
// as the presence list may be redrawn with new elements.
const $target = $(this).closest("li"); const $target = $(this).closest("li");
const user_id = elem_to_user_id($target.find("a")); const user_id = elem_to_user_id($target.find("a"));
// Hiding popovers may mutate current_user_sidebar_user_id.
const previous_user_sidebar_id = current_user_sidebar_user_id;
if (current_user_sidebar_user_id === user_id) { // Hide popovers, but we don't want to hide the sidebars on
// If the popover is already shown, clicking again should toggle it. // smaller browser windows.
// We don't want to hide the sidebars on smaller browser windows.
hide_all_except_sidebars(); hide_all_except_sidebars();
return;
}
hide_all();
if (userlist_placement === "right") { if (previous_user_sidebar_id === user_id) {
show_userlist_sidebar(); // If the popover is already shown, clicking again should toggle it.
} else { return;
// Maintain the same behavior when displaying with the streamlist.
stream_popover.show_streamlist_sidebar();
} }
const user = people.get_by_user_id(user_id); const user = people.get_by_user_id(user_id);