From 434b67caf54a4bf329eb15817eefe4d95cc529c8 Mon Sep 17 00:00:00 2001 From: evykassirer Date: Tue, 2 Jan 2024 22:28:43 -0800 Subject: [PATCH] message_feed_top_notices: Convert module to typescript. --- tools/test-js-with-node | 2 +- ...notices.js => message_feed_top_notices.ts} | 19 ++++++++++++------- web/src/message_lists.ts | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) rename web/src/{message_feed_top_notices.js => message_feed_top_notices.ts} (78%) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index f9719f5c0e..fd0c4731c4 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -130,7 +130,7 @@ EXEMPT_FILES = make_set( "web/src/message_edit_history.js", "web/src/message_events.js", "web/src/message_feed_loading.ts", - "web/src/message_feed_top_notices.js", + "web/src/message_feed_top_notices.ts", "web/src/message_fetch.js", "web/src/message_list.js", "web/src/message_list_data.ts", diff --git a/web/src/message_feed_top_notices.js b/web/src/message_feed_top_notices.ts similarity index 78% rename from web/src/message_feed_top_notices.js rename to web/src/message_feed_top_notices.ts index a3722e1485..11e5c1f03d 100644 --- a/web/src/message_feed_top_notices.js +++ b/web/src/message_feed_top_notices.ts @@ -1,36 +1,40 @@ import $ from "jquery"; +import assert from "minimalistic-assert"; import * as hash_util from "./hash_util"; import * as message_lists from "./message_lists"; +import type {MessageList} from "./message_lists"; import * as narrow_banner from "./narrow_banner"; import * as narrow_state from "./narrow_state"; -function show_history_limit_notice() { +function show_history_limit_notice(): void { $(".top-messages-logo").hide(); $(".history-limited-box").show(); narrow_banner.hide_empty_narrow_message(); } -function hide_history_limit_notice() { +function hide_history_limit_notice(): void { $(".top-messages-logo").show(); $(".history-limited-box").hide(); } -function hide_end_of_results_notice() { +function hide_end_of_results_notice(): void { $(".all-messages-search-caution").hide(); } -function show_end_of_results_notice() { +function show_end_of_results_notice(): void { $(".all-messages-search-caution").show(); // Set the link to point to this search with streams:public added. // Note that element we adjust is not visible to spectators. - const terms = narrow_state.filter().terms(); + const narrow_filter = narrow_state.filter(); + assert(narrow_filter !== undefined); + const terms = narrow_filter.terms(); const update_hash = hash_util.search_public_streams_notice_url(terms); $(".all-messages-search-caution a.search-shared-history").attr("href", update_hash); } -export function update_top_of_narrow_notices(msg_list) { +export function update_top_of_narrow_notices(msg_list: MessageList): void { // Assumes that the current state is all notices hidden (i.e. this // will not hide a notice that should not be there) if (msg_list !== message_lists.current) { @@ -46,6 +50,7 @@ export function update_top_of_narrow_notices(msg_list) { // user moved away from the narrow / filter to Recent Conversations. return; } + assert(filter !== undefined); // Potentially display the notice that lets users know // that not all messages were searched. One could // imagine including `filter.is_keyword_search()` in these @@ -66,7 +71,7 @@ export function update_top_of_narrow_notices(msg_list) { } } -export function hide_top_of_narrow_notices() { +export function hide_top_of_narrow_notices(): void { hide_end_of_results_notice(); hide_history_limit_notice(); } diff --git a/web/src/message_lists.ts b/web/src/message_lists.ts index 890c5c8025..691002cb6a 100644 --- a/web/src/message_lists.ts +++ b/web/src/message_lists.ts @@ -16,7 +16,7 @@ type MessageListView = { _render_win_end: number; }; -type MessageList = { +export type MessageList = { table_name: string; view: MessageListView; selected_id: () => number;