Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
narrow_history: Convert module to typescript.
evykassirerb20694aa07d6
diff --git a/tools/test-js-with-node b/tools/test-js-with-nodeindex 8e2ab4c3135..45fcc836346 100755--- a/tools/test-js-with-node+++ b/tools/test-js-with-node@@ -149,7 +149,7 @@ EXEMPT_FILES = make_set("web/src/modals.ts","web/src/muted_users_ui.js","web/src/narrow.js",- "web/src/narrow_history.js",+ "web/src/narrow_history.ts","web/src/narrow_title.ts","web/src/navbar_alerts.js","web/src/navbar_help_menu.js",diff --git a/web/src/message_lists.ts b/web/src/message_lists.tsindex 9f672d33ac0..bdda2d90021 100644--- a/web/src/message_lists.ts+++ b/web/src/message_lists.ts@@ -3,6 +3,7 @@ import assert from "minimalistic-assert";import * as blueslip from "./blueslip";import * as inbox_util from "./inbox_util";+import type {MessageListData} from "./message_list_data";import type {Message} from "./message_store";import * as recent_view_util from "./recent_view_util";import * as ui_util from "./ui_util";@@ -24,6 +25,7 @@ type MessageList = {all_messages: () => Message[];get: (id: number) => Message | undefined;pre_narrow_offset?: number;+ data: MessageListData;};export let home: MessageList | undefined;diff --git a/web/src/narrow_history.js b/web/src/narrow_history.tssimilarity index 78%rename from web/src/narrow_history.jsrename to web/src/narrow_history.tsindex d12acca9bc6..d40c93780ee 100644--- a/web/src/narrow_history.js+++ b/web/src/narrow_history.ts@@ -7,8 +7,8 @@ import * as narrow_state from "./narrow_state";// Saves the selected message of the narrow in the browser// history, so that we are able to restore it if the user// navigates back to this page.-function _save_narrow_state() {- if (!narrow_state.active()) {+function _save_narrow_state(): void {+ if (!narrow_state.active() || message_lists.current === undefined) {return;}@@ -19,17 +19,19 @@ function _save_narrow_state() {return;}- const narrow_data = {};const narrow_pointer = message_lists.current.selected_id();if (narrow_pointer === -1) {return;}- narrow_data.narrow_pointer = narrow_pointer;const $narrow_row = message_lists.current.selected_row();if ($narrow_row.length === 0) {return;}- narrow_data.narrow_offset = $narrow_row.get_offset_to_window().top;+ const narrow_offset = $narrow_row.get_offset_to_window().top;+ const narrow_data = {+ narrow_pointer,+ narrow_offset,+ };history.replaceState(narrow_data, "", window.location.href);}@@ -37,7 +39,7 @@ function _save_narrow_state() {export const save_narrow_state = _.throttle(_save_narrow_state, 500);// This causes the save to happen right away.-export function save_narrow_state_and_flush() {+export function save_narrow_state_and_flush(): void {save_narrow_state();save_narrow_state.flush();}