navbar_menu: Use switch/case to handle navbar menu toggle.

This commit refactors `change_active_navbar_menu` to use switch/case
to toggle open target menu after closing any open popovers.
This commit is contained in:
Pratik Chanda 2024-11-22 03:16:09 +05:30 committed by Tim Abbott
parent d4bcf5bae3
commit e0e81aa47c
1 changed files with 10 additions and 34 deletions

View File

@ -2,9 +2,9 @@ import $ from "jquery";
import * as gear_menu from "./gear_menu.js";
import * as navbar_help_menu from "./navbar_help_menu.ts";
import {page_params} from "./page_params.ts";
import * as personal_menu_popover from "./personal_menu_popover.ts";
import * as popover_menus from "./popover_menus.ts";
import * as popovers from "./popovers.ts";
export function is_navbar_menus_displayed() {
return (
@ -34,44 +34,20 @@ export function handle_keyboard_events(event_name) {
}
function change_active_navbar_menu(target_menu) {
// We don't need to process arrow keys in navbar menus for spectators
// since they only have gear menu present.
if (
popover_menus.is_personal_menu_popover_displayed() &&
target_menu === "gear-menu" &&
!page_params.is_spectator
) {
// Open gear menu popover on left arrow.
personal_menu_popover.toggle();
gear_menu.toggle();
return true;
}
if (popover_menus.is_help_menu_popover_displayed() && target_menu === "gear-menu") {
// Open gear menu popover on right arrow.
navbar_help_menu.toggle();
gear_menu.toggle();
return true;
}
if (popover_menus.is_gear_menu_popover_displayed()) {
if (target_menu === "gear-menu") {
popovers.hide_all();
switch (target_menu) {
case "gear-menu":
gear_menu.toggle();
return true;
} else if (target_menu === "personal-menu" && !page_params.is_spectator) {
// Open personal menu popover on g + right arrow.
gear_menu.toggle();
personal_menu_popover.toggle();
return true;
} else if (target_menu === "help-menu") {
// Open help menu popover on g + left arrow.
gear_menu.toggle();
case "help-menu":
navbar_help_menu.toggle();
return true;
}
case "personal-menu":
personal_menu_popover.toggle();
return true;
default:
return false;
}
return false;
}
function get_target_navbar_menu(event_name, $current_navbar_menu) {