From 61966e9d6ed55dd8f5ecedea768a78f09cfe63ef Mon Sep 17 00:00:00 2001 From: afeefuddin Date: Sat, 6 Apr 2024 15:25:37 +0530 Subject: [PATCH] compose_tooltips: Convert module to TypeScript. --- tools/test-js-with-node | 2 +- ...ompose_tooltips.js => compose_tooltips.ts} | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) rename web/src/{compose_tooltips.js => compose_tooltips.ts} (95%) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 3c38d0969f..f65760dce0 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -78,7 +78,7 @@ EXEMPT_FILES = make_set( "web/src/compose_setup.js", "web/src/compose_state.ts", "web/src/compose_textarea.ts", - "web/src/compose_tooltips.js", + "web/src/compose_tooltips.ts", "web/src/compose_ui.ts", "web/src/compose_validate.ts", "web/src/composebox_typeahead.js", diff --git a/web/src/compose_tooltips.js b/web/src/compose_tooltips.ts similarity index 95% rename from web/src/compose_tooltips.js rename to web/src/compose_tooltips.ts index 1e99c6ca28..6189e8b234 100644 --- a/web/src/compose_tooltips.js +++ b/web/src/compose_tooltips.ts @@ -1,5 +1,6 @@ import $ from "jquery"; import _ from "lodash"; +import assert from "minimalistic-assert"; import {delegate} from "tippy.js"; import render_drafts_tooltip from "../templates/drafts_tooltip.hbs"; @@ -15,7 +16,7 @@ import {EXTRA_LONG_HOVER_DELAY, INSTANT_HOVER_DELAY, LONG_HOVER_DELAY} from "./t import {parse_html} from "./ui_util"; import {user_settings} from "./user_settings"; -export function initialize() { +export function initialize(): void { delegate("body", { target: [ // Ideally this would be `#compose_buttons .button`, but the @@ -23,7 +24,7 @@ export function initialize() { "#compose_buttons .compose-reply-button-wrapper", "#left_bar_compose_mobile_button_big", "#new_direct_message_button", - ], + ].join(","), delay: EXTRA_LONG_HOVER_DELAY, // Only show on mouseenter since for spectators, clicking on these // buttons opens login modal, and Micromodal returns focus to the @@ -50,18 +51,19 @@ export function initialize() { instance.setContent( parse_html($("#new_direct_message_button_tooltip_template").html()), ); - return; + return undefined; } else if (conversation_type === "stream") { instance.setContent( parse_html($("#new_topic_message_button_tooltip_template").html()), ); - return; + return undefined; } // Use new_stream_message_button_tooltip_template when the // conversation_type is equal to "non-specific" and also as a default fallback. instance.setContent( parse_html($("#new_stream_message_button_tooltip_template").html()), ); + return undefined; }, onHidden(instance) { instance.destroy(); @@ -93,6 +95,7 @@ export function initialize() { // tooltip instantly, to make it clear to the user that the button // is disabled, and why. onTrigger(instance, event) { + assert(event.currentTarget instanceof HTMLElement); if (event.currentTarget.classList.contains("disabled-on-hover")) { instance.setProps({delay: INSTANT_HOVER_DELAY}); } else { @@ -112,7 +115,7 @@ export function initialize() { } if (instance.reference.id === "compose-drafts-button") { const count = - instance.reference.querySelector(".compose-drafts-count").textContent || 0; + instance.reference.querySelector(".compose-drafts-count")!.textContent ?? 0; // Explain that the number in brackets is the number of drafts for this conversation. const draft_count_msg = $t( { @@ -123,7 +126,7 @@ export function initialize() { ); instance.setContent(parse_html(render_drafts_tooltip({draft_count_msg}))); } - return true; + return undefined; }, appendTo: () => document.body, }); @@ -146,7 +149,7 @@ export function initialize() { } else { instance.setContent(parse_html($("#send-ctrl-enter-tooltip-template").html())); } - return true; + return undefined; }, }); @@ -188,7 +191,7 @@ export function initialize() { delegate("body", { // TODO: Might need to target just the Send button itself // in the new design - target: [".disabled-message-send-controls"], + target: ".disabled-message-send-controls", maxWidth: 350, content: () => compose_recipient.get_posting_policy_error_message() ||