From ab03c74314aecc26888a5a348ad338f387a251f8 Mon Sep 17 00:00:00 2001 From: klarabratteby Date: Tue, 22 Oct 2024 13:10:32 +0000 Subject: [PATCH] user_topic_popover: Convert module to TypeScript. --- tools/test-js-with-node | 2 +- ...topic_popover.js => user_topic_popover.ts} | 30 ++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) rename web/src/{user_topic_popover.js => user_topic_popover.ts} (83%) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 61fb25a7e3..62e0bea6a4 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -292,7 +292,7 @@ EXEMPT_FILES = make_set( "web/src/user_sort.ts", "web/src/user_status.ts", "web/src/user_status_ui.ts", - "web/src/user_topic_popover.js", + "web/src/user_topic_popover.ts", "web/src/user_topics.ts", "web/src/user_topics_ui.ts", "web/src/views_util.ts", diff --git a/web/src/user_topic_popover.js b/web/src/user_topic_popover.ts similarity index 83% rename from web/src/user_topic_popover.js rename to web/src/user_topic_popover.ts index 2317157691..80a1155fe3 100644 --- a/web/src/user_topic_popover.js +++ b/web/src/user_topic_popover.ts @@ -1,4 +1,5 @@ import $ from "jquery"; +import assert from "minimalistic-assert"; import render_change_visibility_policy_popover from "../templates/popovers/change_visibility_policy_popover.hbs"; @@ -8,7 +9,7 @@ import {parse_html} from "./ui_util"; import * as user_topics from "./user_topics"; import * as util from "./util"; -export function initialize() { +export function initialize(): void { popover_menus.register_popover_menu(".change_visibility_policy", { theme: "popover-menu", placement: "bottom", @@ -28,15 +29,18 @@ export function initialize() { popover_menus.popover_instances.change_visibility_policy = instance; popover_menus.on_show_prep(instance); const $elt = $(instance.reference).closest(".change_visibility_policy").expectOne(); - const stream_id = $elt.attr("data-stream-id"); - const topic_name = $elt.attr("data-topic-name"); + const stream_id_str = $elt.attr("data-stream-id"); $elt.addClass("visibility-policy-popover-visible"); + assert(stream_id_str !== undefined); + + const stream_id = Number.parseInt(stream_id_str, 10); + const topic_name = $elt.attr("data-topic-name")!; instance.setContent( parse_html( render_change_visibility_policy_popover( popover_menus_data.get_change_visibility_policy_popover_content_context( - Number.parseInt(stream_id, 10), + stream_id, topic_name, ), ), @@ -46,8 +50,11 @@ export function initialize() { onMount(instance) { const $popper = $(instance.popper); const $elt = $(instance.reference).closest(".change_visibility_policy").expectOne(); - const stream_id = Number.parseInt($elt.attr("data-stream-id"), 10); - const topic_name = $elt.attr("data-topic-name"); + const stream_id_str = $elt.attr("data-stream-id"); + assert(stream_id_str !== undefined); + + const stream_id = Number.parseInt(stream_id_str, 10); + const topic_name = $elt.attr("data-topic-name")!; if (!stream_id) { popover_menus.hide_current_popover_if_visible(instance); @@ -58,11 +65,11 @@ export function initialize() { const start_time = Date.now(); const visibility_policy = Number.parseInt( - $(e.currentTarget).attr("data-visibility-policy"), + $(e.currentTarget).attr("data-visibility-policy")!, 10, ); - const success_cb = () => { + const success_cb = (): void => { setTimeout( () => { popover_menus.hide_current_popover_if_visible(instance); @@ -71,7 +78,8 @@ export function initialize() { ); }; - const error_cb = () => { + const error_cb = (): void => { + assert(stream_id !== undefined); const prev_visibility_policy = user_topics.get_topic_visibility_policy( stream_id, topic_name, @@ -86,7 +94,7 @@ export function initialize() { util.get_remaining_time(start_time, 500), ); }; - + assert(stream_id !== undefined); user_topics.set_user_topic_visibility_policy( stream_id, topic_name, @@ -105,7 +113,7 @@ export function initialize() { .expectOne() .removeClass("visibility-policy-popover-visible"); instance.destroy(); - popover_menus.popover_instances.change_visibility_policy = undefined; + popover_menus.popover_instances.change_visibility_policy = null; // If the reference is in recent view / inbox, we would ideally restore focus // to the reference icon here but we don't do that because there are a lot of