From a41d0b16e6451c56b4285d1aadf9afe53808e337 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 14 May 2024 12:49:51 -0700 Subject: [PATCH] user_topics_ui: Convert module to TypeScript. Signed-off-by: Anders Kaseorg --- tools/test-js-with-node | 2 +- web/src/message_lists.ts | 1 + web/src/user_topics.ts | 2 +- web/src/{user_topics_ui.js => user_topics_ui.ts} | 14 ++++++++++---- 4 files changed, 13 insertions(+), 6 deletions(-) rename web/src/{user_topics_ui.js => user_topics_ui.ts} (89%) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index ecab212be9..6943ce06c2 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -284,7 +284,7 @@ EXEMPT_FILES = make_set( "web/src/user_status_ui.ts", "web/src/user_topic_popover.js", "web/src/user_topics.ts", - "web/src/user_topics_ui.js", + "web/src/user_topics_ui.ts", "web/src/views_util.ts", "web/src/zcommand.ts", "web/src/zform.js", diff --git a/web/src/message_lists.ts b/web/src/message_lists.ts index 13cbc5120c..cf411f3c60 100644 --- a/web/src/message_lists.ts +++ b/web/src/message_lists.ts @@ -45,6 +45,7 @@ export type MessageList = { can_mark_messages_read: () => boolean; can_mark_messages_read_without_setting: () => boolean; rerender_view: () => void; + update_muting_and_rerender: () => void; prevent_reading: () => void; resume_reading: () => void; data: MessageListData; diff --git a/web/src/user_topics.ts b/web/src/user_topics.ts index 5a781ed3ac..1a7840bfb4 100644 --- a/web/src/user_topics.ts +++ b/web/src/user_topics.ts @@ -15,7 +15,7 @@ import * as timerender from "./timerender"; import * as ui_report from "./ui_report"; import {get_time_from_date_muted} from "./util"; -type ServerUserTopic = z.infer; +export type ServerUserTopic = z.infer; export type UserTopic = { stream_id: number; diff --git a/web/src/user_topics_ui.js b/web/src/user_topics_ui.ts similarity index 89% rename from web/src/user_topics_ui.js rename to web/src/user_topics_ui.ts index 40415d0e20..58150b6b4a 100644 --- a/web/src/user_topics_ui.js +++ b/web/src/user_topics_ui.ts @@ -1,6 +1,7 @@ import $ from "jquery"; import * as message_lists from "./message_lists"; +import type {Message} from "./message_store"; import * as overlays from "./overlays"; import * as popover_menus from "./popover_menus"; import * as recent_view_ui from "./recent_view_ui"; @@ -9,8 +10,9 @@ import * as stream_list from "./stream_list"; import * as sub_store from "./sub_store"; import * as unread_ui from "./unread_ui"; import * as user_topics from "./user_topics"; +import type {ServerUserTopic} from "./user_topics"; -export function handle_topic_updates(user_topic_event) { +export function handle_topic_updates(user_topic_event: ServerUserTopic): void { // Update the UI after changes in topic visibility policies. user_topics.set_user_topic(user_topic_event); popover_menus.get_topic_menu_popover()?.hide(); @@ -56,7 +58,11 @@ export function handle_topic_updates(user_topic_event) { }, 0); } -export function toggle_topic_visibility_policy(message) { +export function toggle_topic_visibility_policy(message: Message): void { + if (message.type !== "stream") { + return; + } + const stream_id = message.stream_id; const topic = message.topic; @@ -69,8 +75,8 @@ export function toggle_topic_visibility_policy(message) { topic, user_topics.all_visibility_policies.INHERIT, ); - } else if (message.type === "stream") { - if (sub_store.get(stream_id).is_muted) { + } else { + if (sub_store.get(stream_id)?.is_muted) { user_topics.set_user_topic_visibility_policy( stream_id, topic,