From e0fef6fdff2d4053132ab3dfed78ff4d96a374cd Mon Sep 17 00:00:00 2001 From: evykassirer Date: Thu, 21 Dec 2023 21:02:47 -0800 Subject: [PATCH] narrow_title: Migrate module to typescript. --- tools/test-js-with-node | 2 +- web/src/{narrow_title.js => narrow_title.ts} | 17 ++++++++++------- web/src/unread.ts | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) rename web/src/{narrow_title.js => narrow_title.ts} (88%) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 6491cf5409..5e42503d3c 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -150,7 +150,7 @@ EXEMPT_FILES = make_set( "web/src/muted_users_ui.js", "web/src/narrow.js", "web/src/narrow_history.js", - "web/src/narrow_title.js", + "web/src/narrow_title.ts", "web/src/navbar_alerts.js", "web/src/navbar_help_menu.js", "web/src/navbar_menus.js", diff --git a/web/src/narrow_title.js b/web/src/narrow_title.ts similarity index 88% rename from web/src/narrow_title.js rename to web/src/narrow_title.ts index 0ab2650a57..d205d3a301 100644 --- a/web/src/narrow_title.js +++ b/web/src/narrow_title.ts @@ -1,16 +1,20 @@ +import assert from "minimalistic-assert"; + import * as favicon from "./favicon"; +import type {Filter} from "./filter"; import {$t} from "./i18n"; import * as inbox_util from "./inbox_util"; import {page_params} from "./page_params"; import * as people from "./people"; import * as recent_view_util from "./recent_view_util"; import * as unread from "./unread"; +import type {FullUnreadCountsData} from "./unread"; export let unread_count = 0; let pm_count = 0; export let narrow_title = "home"; -export function compute_narrow_title(filter) { +export function compute_narrow_title(filter?: Filter): string { if (filter === undefined) { // "All messages" and "Recent conversations" views have // an `undefined` filter. @@ -18,9 +22,8 @@ export function compute_narrow_title(filter) { return $t({defaultMessage: "Recent conversations"}); } - if (inbox_util.is_visible()) { - return $t({defaultMessage: "Inbox"}); - } + assert(inbox_util.is_visible()); + return $t({defaultMessage: "Inbox"}); } const filter_title = filter.get_title(); @@ -76,7 +79,7 @@ export function compute_narrow_title(filter) { return filter_title; } -export function redraw_title() { +export function redraw_title(): void { // Update window title to reflect unread messages in current view const new_title = (unread_count ? "(" + unread_count + ") " : "") + @@ -89,7 +92,7 @@ export function redraw_title() { document.title = new_title; } -export function update_unread_counts(counts) { +export function update_unread_counts(counts: FullUnreadCountsData): void { const new_unread_count = unread.calculate_notifiable_count(counts); const new_pm_count = counts.direct_message_count; if (new_unread_count === unread_count && new_pm_count === pm_count) { @@ -111,7 +114,7 @@ export function update_unread_counts(counts) { redraw_title(); } -export function update_narrow_title(filter) { +export function update_narrow_title(filter: Filter): void { narrow_title = compute_narrow_title(filter); redraw_title(); } diff --git a/web/src/unread.ts b/web/src/unread.ts index 46e6cee6af..166de862a3 100644 --- a/web/src/unread.ts +++ b/web/src/unread.ts @@ -836,7 +836,7 @@ export function get_unread_topics(include_per_topic_latest_msg_id = false): Unre ); } -type FullUnreadCountsData = { +export type FullUnreadCountsData = { direct_message_count: number; mentioned_message_count: number; direct_message_with_mention_count: number;