mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 17:36:27 +00:00
views_util: Cut import of narrow.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
e8ced3e74a
commit
63b4e74cea
@@ -305,6 +305,12 @@ function on_hidden_callback() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function handle_middle_pane_transition() {
|
||||||
|
if (compose_state.composing) {
|
||||||
|
update_narrow_to_recipient_visibility();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function initialize() {
|
export function initialize() {
|
||||||
new dropdown_widget.DropdownWidget({
|
new dropdown_widget.DropdownWidget({
|
||||||
widget_name: "compose_select_recipient",
|
widget_name: "compose_select_recipient",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
|
|
||||||
|
import * as blueslip from "./blueslip";
|
||||||
import * as inbox_util from "./inbox_util";
|
import * as inbox_util from "./inbox_util";
|
||||||
import * as recent_view_util from "./recent_view_util";
|
import * as recent_view_util from "./recent_view_util";
|
||||||
import * as ui_util from "./ui_util";
|
import * as ui_util from "./ui_util";
|
||||||
@@ -34,6 +35,23 @@ export function update_recipient_bar_background_color() {
|
|||||||
inbox_util.update_stream_colors();
|
inbox_util.update_stream_colors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function save_pre_narrow_offset_for_reload() {
|
||||||
|
if (current.selected_id() !== -1) {
|
||||||
|
if (current.selected_row().length === 0) {
|
||||||
|
blueslip.debug("narrow.activate missing selected row", {
|
||||||
|
selected_id: current.selected_id(),
|
||||||
|
selected_idx: current.selected_idx(),
|
||||||
|
selected_idx_exact: current
|
||||||
|
.all_messages()
|
||||||
|
.indexOf(current.get(current.selected_id())),
|
||||||
|
render_start: current.view._render_win_start,
|
||||||
|
render_end: current.view._render_win_end,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
current.pre_narrow_offset = current.selected_row().get_offset_to_window().top;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function initialize() {
|
export function initialize() {
|
||||||
// For users with automatic color scheme, we need to detect change
|
// For users with automatic color scheme, we need to detect change
|
||||||
// in `prefers-color-scheme`as it changes based on time.
|
// in `prefers-color-scheme`as it changes based on time.
|
||||||
|
|||||||
@@ -55,27 +55,6 @@ import * as widgetize from "./widgetize";
|
|||||||
|
|
||||||
const LARGER_THAN_MAX_MESSAGE_ID = 10000000000000000;
|
const LARGER_THAN_MAX_MESSAGE_ID = 10000000000000000;
|
||||||
|
|
||||||
export function save_pre_narrow_offset_for_reload() {
|
|
||||||
if (message_lists.current.selected_id() !== -1) {
|
|
||||||
if (message_lists.current.selected_row().length === 0) {
|
|
||||||
blueslip.debug("narrow.activate missing selected row", {
|
|
||||||
selected_id: message_lists.current.selected_id(),
|
|
||||||
selected_idx: message_lists.current.selected_idx(),
|
|
||||||
selected_idx_exact: message_lists.current
|
|
||||||
.all_messages()
|
|
||||||
.indexOf(message_lists.current.get(message_lists.current.selected_id())),
|
|
||||||
render_start: message_lists.current.view._render_win_start,
|
|
||||||
render_end: message_lists.current.view._render_win_end,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
message_lists.current.pre_narrow_offset = message_lists.current
|
|
||||||
.selected_row()
|
|
||||||
.get_offset_to_window().top;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export let has_shown_message_list_view = false;
|
|
||||||
|
|
||||||
export function reset_ui_state() {
|
export function reset_ui_state() {
|
||||||
// Resets the state of various visual UI elements that are
|
// Resets the state of various visual UI elements that are
|
||||||
// a function of the current narrow.
|
// a function of the current narrow.
|
||||||
@@ -85,12 +64,6 @@ export function reset_ui_state() {
|
|||||||
unread_ui.reset_unread_banner();
|
unread_ui.reset_unread_banner();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handle_middle_pane_transition() {
|
|
||||||
if (compose_state.composing) {
|
|
||||||
compose_recipient.update_narrow_to_recipient_visibility();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function changehash(newhash) {
|
export function changehash(newhash) {
|
||||||
if (browser_history.state.changing_hash) {
|
if (browser_history.state.changing_hash) {
|
||||||
return;
|
return;
|
||||||
@@ -355,7 +328,7 @@ export function activate(raw_operators, opts) {
|
|||||||
// We must instead be switching from another message view.
|
// We must instead be switching from another message view.
|
||||||
// Save the scroll position in that message list, so that
|
// Save the scroll position in that message list, so that
|
||||||
// we can restore it if/when we later navigate back to that view.
|
// we can restore it if/when we later navigate back to that view.
|
||||||
save_pre_narrow_offset_for_reload();
|
message_lists.save_pre_narrow_offset_for_reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
// most users aren't going to send a bunch of a out-of-narrow messages
|
// most users aren't going to send a bunch of a out-of-narrow messages
|
||||||
@@ -392,7 +365,7 @@ export function activate(raw_operators, opts) {
|
|||||||
// populating the new narrow, so we update our narrow_state.
|
// populating the new narrow, so we update our narrow_state.
|
||||||
// From here on down, any calls to the narrow_state API will
|
// From here on down, any calls to the narrow_state API will
|
||||||
// reflect the upcoming narrow.
|
// reflect the upcoming narrow.
|
||||||
has_shown_message_list_view = true;
|
narrow_state.set_has_shown_message_list_view();
|
||||||
narrow_state.set_current_filter(filter);
|
narrow_state.set_current_filter(filter);
|
||||||
|
|
||||||
const excludes_muted_topics = narrow_state.excludes_muted_topics();
|
const excludes_muted_topics = narrow_state.excludes_muted_topics();
|
||||||
@@ -507,7 +480,7 @@ export function activate(raw_operators, opts) {
|
|||||||
|
|
||||||
// It is important to call this after other important updates
|
// It is important to call this after other important updates
|
||||||
// like narrow filter and compose recipients happen.
|
// like narrow filter and compose recipients happen.
|
||||||
handle_middle_pane_transition();
|
compose_recipient.handle_middle_pane_transition();
|
||||||
|
|
||||||
const post_span = span.startChild({
|
const post_span = span.startChild({
|
||||||
op: "function",
|
op: "function",
|
||||||
@@ -1025,7 +998,7 @@ export function deactivate(coming_from_all_messages = true, is_actively_scrollin
|
|||||||
}
|
}
|
||||||
|
|
||||||
narrow_state.reset_current_filter();
|
narrow_state.reset_current_filter();
|
||||||
has_shown_message_list_view = true;
|
narrow_state.set_has_shown_message_list_view();
|
||||||
|
|
||||||
$("body").removeClass("narrowed_view");
|
$("body").removeClass("narrowed_view");
|
||||||
$("#zfilt").removeClass("focused-message-list");
|
$("#zfilt").removeClass("focused-message-list");
|
||||||
@@ -1035,7 +1008,7 @@ export function deactivate(coming_from_all_messages = true, is_actively_scrollin
|
|||||||
condense.condense_and_collapse($("#zhome div.message_row"));
|
condense.condense_and_collapse($("#zhome div.message_row"));
|
||||||
|
|
||||||
reset_ui_state();
|
reset_ui_state();
|
||||||
handle_middle_pane_transition();
|
compose_recipient.handle_middle_pane_transition();
|
||||||
save_narrow();
|
save_narrow();
|
||||||
|
|
||||||
if (message_lists.current.selected_id() !== -1) {
|
if (message_lists.current.selected_id() !== -1) {
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import * as unread from "./unread";
|
|||||||
|
|
||||||
let current_filter;
|
let current_filter;
|
||||||
|
|
||||||
|
export let has_shown_message_list_view = false;
|
||||||
|
|
||||||
export function reset_current_filter() {
|
export function reset_current_filter() {
|
||||||
current_filter = undefined;
|
current_filter = undefined;
|
||||||
}
|
}
|
||||||
@@ -369,3 +371,7 @@ export function is_for_stream_id(stream_id) {
|
|||||||
|
|
||||||
return stream_id === narrow_sub.stream_id;
|
return stream_id === narrow_sub.stream_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function set_has_shown_message_list_view() {
|
||||||
|
has_shown_message_list_view = true;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
|
|
||||||
|
import * as compose_recipient from "./compose_recipient";
|
||||||
|
import * as message_lists from "./message_lists";
|
||||||
import * as message_view_header from "./message_view_header";
|
import * as message_view_header from "./message_view_header";
|
||||||
import * as narrow from "./narrow";
|
|
||||||
import * as narrow_state from "./narrow_state";
|
import * as narrow_state from "./narrow_state";
|
||||||
import * as narrow_title from "./narrow_title";
|
import * as narrow_title from "./narrow_title";
|
||||||
import * as navigate from "./navigate";
|
import * as navigate from "./navigate";
|
||||||
@@ -12,8 +13,8 @@ import * as stream_list from "./stream_list";
|
|||||||
import * as unread_ui from "./unread_ui";
|
import * as unread_ui from "./unread_ui";
|
||||||
|
|
||||||
export function show(opts) {
|
export function show(opts) {
|
||||||
if (narrow.has_shown_message_list_view) {
|
if (narrow_state.has_shown_message_list_view) {
|
||||||
narrow.save_pre_narrow_offset_for_reload();
|
message_lists.save_pre_narrow_offset_for_reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.is_visible()) {
|
if (opts.is_visible()) {
|
||||||
@@ -38,7 +39,7 @@ export function show(opts) {
|
|||||||
narrow_state.reset_current_filter();
|
narrow_state.reset_current_filter();
|
||||||
narrow_title.update_narrow_title(narrow_state.filter());
|
narrow_title.update_narrow_title(narrow_state.filter());
|
||||||
message_view_header.render_title_area();
|
message_view_header.render_title_area();
|
||||||
narrow.handle_middle_pane_transition();
|
compose_recipient.handle_middle_pane_transition();
|
||||||
search.clear_search_form();
|
search.clear_search_form();
|
||||||
opts.complete_rerender();
|
opts.complete_rerender();
|
||||||
resize.update_recent_view_filters_height();
|
resize.update_recent_view_filters_height();
|
||||||
|
|||||||
@@ -83,16 +83,17 @@ function test_helper({override}) {
|
|||||||
stub(compose_banner, "clear_message_sent_banners");
|
stub(compose_banner, "clear_message_sent_banners");
|
||||||
stub(compose_actions, "on_narrow");
|
stub(compose_actions, "on_narrow");
|
||||||
stub(compose_closed_ui, "update_reply_recipient_label");
|
stub(compose_closed_ui, "update_reply_recipient_label");
|
||||||
|
stub(compose_recipient, "handle_middle_pane_transition");
|
||||||
stub(narrow_history, "save_narrow_state_and_flush");
|
stub(narrow_history, "save_narrow_state_and_flush");
|
||||||
stub(message_feed_loading, "hide_indicators");
|
stub(message_feed_loading, "hide_indicators");
|
||||||
stub(message_feed_top_notices, "hide_top_of_narrow_notices");
|
stub(message_feed_top_notices, "hide_top_of_narrow_notices");
|
||||||
|
stub(message_lists, "save_pre_narrow_offset_for_reload");
|
||||||
stub(narrow_title, "update_narrow_title");
|
stub(narrow_title, "update_narrow_title");
|
||||||
stub(stream_list, "handle_narrow_activated");
|
stub(stream_list, "handle_narrow_activated");
|
||||||
stub(message_view_header, "render_title_area");
|
stub(message_view_header, "render_title_area");
|
||||||
stub(message_viewport, "stop_auto_scrolling");
|
stub(message_viewport, "stop_auto_scrolling");
|
||||||
stub(left_sidebar_navigation_area, "handle_narrow_activated");
|
stub(left_sidebar_navigation_area, "handle_narrow_activated");
|
||||||
stub(typing_events, "render_notifications_for_narrow");
|
stub(typing_events, "render_notifications_for_narrow");
|
||||||
stub(compose_recipient, "update_narrow_to_recipient_visibility");
|
|
||||||
stub(unread_ops, "process_visible");
|
stub(unread_ops, "process_visible");
|
||||||
stub(compose_closed_ui, "update_buttons_for_stream");
|
stub(compose_closed_ui, "update_buttons_for_stream");
|
||||||
stub(compose_closed_ui, "update_buttons_for_private");
|
stub(compose_closed_ui, "update_buttons_for_private");
|
||||||
@@ -186,6 +187,7 @@ run_test("basics", ({override}) => {
|
|||||||
helper.assert_events([
|
helper.assert_events([
|
||||||
[message_feed_top_notices, "hide_top_of_narrow_notices"],
|
[message_feed_top_notices, "hide_top_of_narrow_notices"],
|
||||||
[message_feed_loading, "hide_indicators"],
|
[message_feed_loading, "hide_indicators"],
|
||||||
|
[message_lists, "save_pre_narrow_offset_for_reload"],
|
||||||
[compose_banner, "clear_message_sent_banners"],
|
[compose_banner, "clear_message_sent_banners"],
|
||||||
[unread_ops, "process_visible"],
|
[unread_ops, "process_visible"],
|
||||||
[narrow_history, "save_narrow_state_and_flush"],
|
[narrow_history, "save_narrow_state_and_flush"],
|
||||||
@@ -199,7 +201,7 @@ run_test("basics", ({override}) => {
|
|||||||
[left_sidebar_navigation_area, "handle_narrow_activated"],
|
[left_sidebar_navigation_area, "handle_narrow_activated"],
|
||||||
[stream_list, "handle_narrow_activated"],
|
[stream_list, "handle_narrow_activated"],
|
||||||
[compose_actions, "on_narrow"],
|
[compose_actions, "on_narrow"],
|
||||||
[compose_recipient, "update_narrow_to_recipient_visibility"],
|
[compose_recipient, "handle_middle_pane_transition"],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
message_lists.current.selected_id = () => -1;
|
message_lists.current.selected_id = () => -1;
|
||||||
|
|||||||
@@ -141,11 +141,6 @@ mock_esm("../src/user_topics", {
|
|||||||
},
|
},
|
||||||
all_visibility_policies,
|
all_visibility_policies,
|
||||||
});
|
});
|
||||||
const narrow = mock_esm("../src/narrow", {
|
|
||||||
hide_unread_banner: noop,
|
|
||||||
handle_middle_pane_transition: noop,
|
|
||||||
has_shown_message_list_view: true,
|
|
||||||
});
|
|
||||||
mock_esm("../src/narrow_title", {
|
mock_esm("../src/narrow_title", {
|
||||||
update_narrow_title() {},
|
update_narrow_title() {},
|
||||||
});
|
});
|
||||||
@@ -452,9 +447,7 @@ function test(label, f) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
test("test_recent_view_show", ({mock_template, override}) => {
|
test("test_recent_view_show", ({mock_template}) => {
|
||||||
override(narrow, "save_pre_narrow_offset_for_reload", () => {});
|
|
||||||
|
|
||||||
// Note: unread count and urls are fake,
|
// Note: unread count and urls are fake,
|
||||||
// since they are generated in external libraries
|
// since they are generated in external libraries
|
||||||
// and are not to be tested here.
|
// and are not to be tested here.
|
||||||
|
|||||||
Reference in New Issue
Block a user