From b20694aa07d65b5bce6058e1f287c88ae6473fcc Mon Sep 17 00:00:00 2001 From: evykassirer Date: Sun, 24 Dec 2023 15:30:42 -0800 Subject: [PATCH] narrow_history: Convert module to typescript. --- tools/test-js-with-node | 2 +- web/src/message_lists.ts | 2 ++ web/src/{narrow_history.js => narrow_history.ts} | 14 ++++++++------ 3 files changed, 11 insertions(+), 7 deletions(-) rename web/src/{narrow_history.js => narrow_history.ts} (78%) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 8e2ab4c313..45fcc83634 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.ts index 9f672d33ac..bdda2d9002 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.ts similarity index 78% rename from web/src/narrow_history.js rename to web/src/narrow_history.ts index d12acca9bc..d40c93780e 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(); }