narrow_banner: Convert module to typescript.

This commit is contained in:
evykassirer 2024-01-02 22:18:09 -08:00 committed by Tim Abbott
parent 08bee0f180
commit cd9a479a7e
3 changed files with 14 additions and 9 deletions

View File

@ -1,6 +1,8 @@
import $ from "jquery"; import $ from "jquery";
import assert from "minimalistic-assert";
import {$t, $t_html} from "./i18n"; import {$t, $t_html} from "./i18n";
import type {NarrowBannerData, SearchData} from "./narrow_error";
import {narrow_error} from "./narrow_error"; import {narrow_error} from "./narrow_error";
import * as narrow_state from "./narrow_state"; import * as narrow_state from "./narrow_state";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
@ -24,13 +26,14 @@ const SPECTATOR_STREAM_NARROW_BANNER = {
), ),
}; };
function retrieve_search_query_data() { function retrieve_search_query_data(): SearchData {
// when search bar contains multiple filters, only retrieve search queries // when search bar contains multiple filters, only retrieve search queries
const current_filter = narrow_state.filter(); const current_filter = narrow_state.filter();
assert(current_filter !== undefined);
const search_query = current_filter.operands("search")[0]; const search_query = current_filter.operands("search")[0];
const query_words = search_query.split(" "); const query_words = search_query.split(" ");
const search_string_result = { const search_string_result: SearchData = {
query_words: [], query_words: [],
has_stop_word: false, has_stop_word: false,
}; };
@ -66,7 +69,7 @@ function retrieve_search_query_data() {
return search_string_result; return search_string_result;
} }
function pick_empty_narrow_banner() { function pick_empty_narrow_banner(): NarrowBannerData {
const default_banner = { const default_banner = {
title: $t({defaultMessage: "There are no messages here."}), title: $t({defaultMessage: "There are no messages here."}),
// Spectators cannot start a conversation. // Spectators cannot start a conversation.
@ -248,7 +251,7 @@ function pick_empty_narrow_banner() {
return SPECTATOR_STREAM_NARROW_BANNER; return SPECTATOR_STREAM_NARROW_BANNER;
} }
function can_toggle_narrowed_stream() { function can_toggle_narrowed_stream(): boolean | undefined {
const stream_name = narrow_state.stream_name(); const stream_name = narrow_state.stream_name();
if (!stream_name) { if (!stream_name) {
@ -305,6 +308,7 @@ function pick_empty_narrow_banner() {
}; };
} }
const user_ids = people.emails_strings_to_user_ids_array(first_operand); const user_ids = people.emails_strings_to_user_ids_array(first_operand);
assert(user_ids !== undefined);
if ( if (
page_params.realm_private_message_policy === page_params.realm_private_message_policy ===
settings_config.private_message_policy_values.disabled.code && settings_config.private_message_policy_values.disabled.code &&
@ -430,12 +434,12 @@ function pick_empty_narrow_banner() {
return default_banner; return default_banner;
} }
export function show_empty_narrow_message() { export function show_empty_narrow_message(): void {
$(".empty_feed_notice_main").empty(); $(".empty_feed_notice_main").empty();
const rendered_narrow_banner = narrow_error(pick_empty_narrow_banner()); const rendered_narrow_banner = narrow_error(pick_empty_narrow_banner());
$(".empty_feed_notice_main").html(rendered_narrow_banner); $(".empty_feed_notice_main").html(rendered_narrow_banner);
} }
export function hide_empty_narrow_message() { export function hide_empty_narrow_message(): void {
$(".empty_feed_notice_main").empty(); $(".empty_feed_notice_main").empty();
} }

View File

@ -5,14 +5,14 @@ type QueryWord = {
is_stop_word: boolean; is_stop_word: boolean;
}; };
type SearchData = { export type SearchData = {
query_word: QueryWord[]; query_words: QueryWord[];
has_stop_word: boolean; has_stop_word: boolean;
stream_query?: string; stream_query?: string;
topic_query?: string; topic_query?: string;
}; };
type NarrowBannerData = { export type NarrowBannerData = {
title: string; title: string;
html?: string; html?: string;
search_data?: SearchData; search_data?: SearchData;

View File

@ -111,6 +111,7 @@ export const page_params: {
show_plans: boolean; show_plans: boolean;
show_webathena: boolean; show_webathena: boolean;
sponsorship_pending: boolean; sponsorship_pending: boolean;
stop_words: string[];
translation_data: Record<string, string>; translation_data: Record<string, string>;
user_id: number; user_id: number;
zulip_merge_base: string; zulip_merge_base: string;