From 860150525c3a663ffc0fe8cab61fcc87a279b30b Mon Sep 17 00:00:00 2001 From: evykassirer Date: Fri, 9 Feb 2024 16:51:53 -0800 Subject: [PATCH] sidebar_ui: Convert module to typescript. --- tools/test-js-with-node | 2 +- web/src/{sidebar_ui.js => sidebar_ui.ts} | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) rename web/src/{sidebar_ui.js => sidebar_ui.ts} (91%) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index aed230bcd6..d80949d188 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -221,7 +221,7 @@ EXEMPT_FILES = make_set( "web/src/settings_user_topics.js", "web/src/settings_users.js", "web/src/setup.ts", - "web/src/sidebar_ui.js", + "web/src/sidebar_ui.ts", "web/src/spectators.ts", "web/src/spoilers.ts", "web/src/starred_messages_ui.js", diff --git a/web/src/sidebar_ui.js b/web/src/sidebar_ui.ts similarity index 91% rename from web/src/sidebar_ui.js rename to web/src/sidebar_ui.ts index 44c594da46..b71e47a954 100644 --- a/web/src/sidebar_ui.js +++ b/web/src/sidebar_ui.ts @@ -15,33 +15,33 @@ import {user_settings} from "./user_settings"; export let left_sidebar_expanded_as_overlay = false; export let right_sidebar_expanded_as_overlay = false; -export function hide_userlist_sidebar() { +export function hide_userlist_sidebar(): void { $(".app-main .column-right").removeClass("expanded"); right_sidebar_expanded_as_overlay = false; } -export function show_userlist_sidebar() { +export function show_userlist_sidebar(): void { $(".app-main .column-right").addClass("expanded"); resize.resize_page_components(); right_sidebar_expanded_as_overlay = true; } -export function show_streamlist_sidebar() { +export function show_streamlist_sidebar(): void { $(".app-main .column-left").addClass("expanded"); resize.resize_stream_filters_container(); left_sidebar_expanded_as_overlay = true; } -export function hide_streamlist_sidebar() { +export function hide_streamlist_sidebar(): void { $(".app-main .column-left").removeClass("expanded"); left_sidebar_expanded_as_overlay = false; } -export function any_sidebar_expanded_as_overlay() { +export function any_sidebar_expanded_as_overlay(): boolean { return left_sidebar_expanded_as_overlay || right_sidebar_expanded_as_overlay; } -export function update_invite_user_option() { +export function update_invite_user_option(): void { if ( !settings_data.user_can_invite_users_by_email() && !settings_data.user_can_create_multiuse_invite() @@ -52,12 +52,12 @@ export function update_invite_user_option() { } } -export function hide_all() { +export function hide_all(): void { hide_streamlist_sidebar(); hide_userlist_sidebar(); } -export function initialize() { +export function initialize(): void { $("body").on("click", ".login_button", (e) => { e.preventDefault(); e.stopPropagation(); @@ -94,6 +94,10 @@ export function initialize() { return; } + if (!(e.target instanceof Element)) { + return; + } + const $elt = $(e.target); // Since sidebar toggle buttons have their own click handlers, don't handle them here. if ( @@ -135,7 +139,7 @@ export function initialize() { ); } -export function initialize_left_sidebar() { +export function initialize_left_sidebar(): void { const rendered_sidebar = render_left_sidebar({ is_guest: current_user.is_guest, development_environment: page_params.development_environment, @@ -151,7 +155,7 @@ export function initialize_left_sidebar() { $("#left-sidebar-container").html(rendered_sidebar); } -export function initialize_right_sidebar() { +export function initialize_right_sidebar(): void { const rendered_sidebar = render_right_sidebar({ realm_rendered_description: page_params.realm_rendered_description, });