mirror of https://github.com/zulip/zulip.git
narrow_history: Convert module to typescript.
This commit is contained in:
parent
e0a10c2d94
commit
b20694aa07
|
@ -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",
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
Loading…
Reference in New Issue