user_topic_popover: Convert module to TypeScript.

This commit is contained in:
klarabratteby 2024-10-22 13:10:32 +00:00 committed by Tim Abbott
parent a601715e37
commit ab03c74314
2 changed files with 20 additions and 12 deletions

View File

@ -292,7 +292,7 @@ EXEMPT_FILES = make_set(
"web/src/user_sort.ts", "web/src/user_sort.ts",
"web/src/user_status.ts", "web/src/user_status.ts",
"web/src/user_status_ui.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.ts",
"web/src/user_topics_ui.ts", "web/src/user_topics_ui.ts",
"web/src/views_util.ts", "web/src/views_util.ts",

View File

@ -1,4 +1,5 @@
import $ from "jquery"; import $ from "jquery";
import assert from "minimalistic-assert";
import render_change_visibility_policy_popover from "../templates/popovers/change_visibility_policy_popover.hbs"; 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 user_topics from "./user_topics";
import * as util from "./util"; import * as util from "./util";
export function initialize() { export function initialize(): void {
popover_menus.register_popover_menu(".change_visibility_policy", { popover_menus.register_popover_menu(".change_visibility_policy", {
theme: "popover-menu", theme: "popover-menu",
placement: "bottom", placement: "bottom",
@ -28,15 +29,18 @@ export function initialize() {
popover_menus.popover_instances.change_visibility_policy = instance; popover_menus.popover_instances.change_visibility_policy = instance;
popover_menus.on_show_prep(instance); popover_menus.on_show_prep(instance);
const $elt = $(instance.reference).closest(".change_visibility_policy").expectOne(); const $elt = $(instance.reference).closest(".change_visibility_policy").expectOne();
const stream_id = $elt.attr("data-stream-id"); const stream_id_str = $elt.attr("data-stream-id");
const topic_name = $elt.attr("data-topic-name");
$elt.addClass("visibility-policy-popover-visible"); $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( instance.setContent(
parse_html( parse_html(
render_change_visibility_policy_popover( render_change_visibility_policy_popover(
popover_menus_data.get_change_visibility_policy_popover_content_context( popover_menus_data.get_change_visibility_policy_popover_content_context(
Number.parseInt(stream_id, 10), stream_id,
topic_name, topic_name,
), ),
), ),
@ -46,8 +50,11 @@ export function initialize() {
onMount(instance) { onMount(instance) {
const $popper = $(instance.popper); const $popper = $(instance.popper);
const $elt = $(instance.reference).closest(".change_visibility_policy").expectOne(); const $elt = $(instance.reference).closest(".change_visibility_policy").expectOne();
const stream_id = Number.parseInt($elt.attr("data-stream-id"), 10); const stream_id_str = $elt.attr("data-stream-id");
const topic_name = $elt.attr("data-topic-name"); 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) { if (!stream_id) {
popover_menus.hide_current_popover_if_visible(instance); popover_menus.hide_current_popover_if_visible(instance);
@ -58,11 +65,11 @@ export function initialize() {
const start_time = Date.now(); const start_time = Date.now();
const visibility_policy = Number.parseInt( const visibility_policy = Number.parseInt(
$(e.currentTarget).attr("data-visibility-policy"), $(e.currentTarget).attr("data-visibility-policy")!,
10, 10,
); );
const success_cb = () => { const success_cb = (): void => {
setTimeout( setTimeout(
() => { () => {
popover_menus.hide_current_popover_if_visible(instance); 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( const prev_visibility_policy = user_topics.get_topic_visibility_policy(
stream_id, stream_id,
topic_name, topic_name,
@ -86,7 +94,7 @@ export function initialize() {
util.get_remaining_time(start_time, 500), util.get_remaining_time(start_time, 500),
); );
}; };
assert(stream_id !== undefined);
user_topics.set_user_topic_visibility_policy( user_topics.set_user_topic_visibility_policy(
stream_id, stream_id,
topic_name, topic_name,
@ -105,7 +113,7 @@ export function initialize() {
.expectOne() .expectOne()
.removeClass("visibility-policy-popover-visible"); .removeClass("visibility-policy-popover-visible");
instance.destroy(); 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 // 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 // to the reference icon here but we don't do that because there are a lot of