popovers: Refactor compose_enter_sends popover.

This commit is contained in:
Daniil Fadeev
2023-03-28 18:28:17 +04:00
committed by Tim Abbott
parent 39936dee5d
commit 602be3ed68
2 changed files with 9 additions and 5 deletions

View File

@@ -40,7 +40,6 @@ import {parse_html} from "./ui_util";
import * as unread_ops from "./unread_ops";
import {user_settings} from "./user_settings";
export let compose_enter_sends_popover_displayed = false;
let message_actions_popover_keyboard_toggle = false;
const popover_instances = {
@@ -51,6 +50,7 @@ const popover_instances = {
message_actions: null,
stream_settings: null,
compose_mobile_button: null,
compose_enter_sends: null,
};
export function sidebar_menu_instance_handle_keyboard(instance, key) {
@@ -70,6 +70,10 @@ export function get_starred_messages_popover() {
return popover_instances.starred_messages;
}
export function is_compose_enter_sends_popover_displayed() {
return popover_instances.compose_enter_sends?.state.isVisible;
}
function get_popover_items_for_instance(instance) {
const $current_elem = $(instance.popper);
const class_name = $current_elem.attr("class");
@@ -116,7 +120,7 @@ const left_sidebar_tippy_options = {
};
export function any_active() {
return compose_enter_sends_popover_displayed || get_visible_instance();
return Boolean(get_visible_instance());
}
function on_show_prep(instance) {
@@ -279,9 +283,9 @@ export function initialize() {
}),
),
);
compose_enter_sends_popover_displayed = true;
},
onMount(instance) {
popover_instances.compose_enter_sends = instance;
common.adjust_mac_kbd_tags(".enter_sends_choices kbd");
$(instance.popper).one("click", ".enter_sends_choice", (e) => {
@@ -307,7 +311,7 @@ export function initialize() {
},
onHidden(instance) {
instance.destroy();
compose_enter_sends_popover_displayed = false;
popover_instances.compose_enter_sends = undefined;
},
});

View File

@@ -289,7 +289,7 @@ export function initialize() {
content: $t({defaultMessage: "Change send shortcut"}),
onShow() {
// Don't show tooltip if the popover is displayed.
if (popover_menus.compose_enter_sends_popover_displayed) {
if (popover_menus.is_compose_enter_sends_popover_displayed()) {
return false;
}
return true;