Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

left_sidebar: Support filtering all items using the search input.

Aman Agrawal78a3ef56e437
diff --git a/web/e2e-tests/message-basics.test.ts b/web/e2e-tests/message-basics.test.ts
index bd8027b60e5..4c1efc63246 100644
--- a/web/e2e-tests/message-basics.test.ts
+++ b/web/e2e-tests/message-basics.test.ts
@@ -7,7 +7,7 @@ import * as common from "./lib/common.ts";
async function get_stream_li(page: Page, stream_name: string): Promise<string> {
const stream_id = await common.get_stream_id(page, stream_name);
assert.ok(stream_id !== undefined);
- return `#stream_filters [data-stream-id="${CSS.escape(stream_id.toString())}"]`;
+ return `#stream_filters .narrow-filter[data-stream-id="${CSS.escape(stream_id.toString())}"]`;
}
async function expect_home(page: Page): Promise<void> {
@@ -304,7 +304,7 @@ async function test_search_venice(page: Page): Promise<void> {
await common.clear_and_type(page, ".left-sidebar-search-input", "vEnI"); // Must be case insensitive.
await page.waitForSelector(await get_stream_li(page, "Denmark"), {hidden: true});
await page.waitForSelector(await get_stream_li(page, "Verona"), {hidden: true});
- await page.waitForSelector((await get_stream_li(page, "Venice")) + ".highlighted_row", {
+ await page.waitForSelector((await get_stream_li(page, "Venice")) + " .highlighted_row", {
visible: true,
});
@@ -328,29 +328,17 @@ async function test_stream_search_filters_stream_list(page: Page): Promise<void>
// Enter the search box and test highlighted suggestion
await page.click(".left-sidebar-search-input");
- await page.waitForSelector("#stream_filters .highlighted_row", {visible: true});
- // First stream in list gets highlighted on clicking search.
- await page.waitForSelector((await get_stream_li(page, "core team")) + ".highlighted_row", {
- visible: true,
- });
+ await page.waitForSelector(".top_left_inbox.top_left_row.highlighted_row", {visible: true});
- await page.waitForSelector((await get_stream_li(page, "Denmark")) + ".highlighted_row", {
- hidden: true,
- });
- await page.waitForSelector((await get_stream_li(page, "sandbox")) + ".highlighted_row", {
- hidden: true,
- });
- await page.waitForSelector((await get_stream_li(page, "Venice")) + ".highlighted_row", {
- hidden: true,
- });
- await page.waitForSelector((await get_stream_li(page, "Verona")) + ".highlighted_row", {
- hidden: true,
- });
- await page.waitForSelector((await get_stream_li(page, "Zulip")) + ".highlighted_row", {
+ await page.waitForSelector((await get_stream_li(page, "Verona")) + " .highlighted_row", {
hidden: true,
});
// Navigate through suggestions using arrow keys
+ // Reach core team
+ for (let i = 0; i < 10; i += 1) {
+ await arrow(page, "Down");
+ }
await arrow(page, "Down"); // core team -> Denmark
await arrow(page, "Down"); // Denmark -> sandbox
await arrow(page, "Up"); // sandbox -> Denmark
@@ -361,20 +349,20 @@ async function test_stream_search_filters_stream_list(page: Page): Promise<void>
await arrow(page, "Down"); // sandbox-> Venice
await arrow(page, "Down"); // Venice -> Verona
- await page.waitForSelector((await get_stream_li(page, "Verona")) + ".highlighted_row", {
+ await page.waitForSelector((await get_stream_li(page, "Verona")) + " .highlighted_row", {
visible: true,
});
- await page.waitForSelector((await get_stream_li(page, "core team")) + ".highlighted_row", {
+ await page.waitForSelector((await get_stream_li(page, "core team")) + " .highlighted_row", {
hidden: true,
});
- await page.waitForSelector((await get_stream_li(page, "Denmark")) + ".highlighted_row", {
+ await page.waitForSelector((await get_stream_li(page, "Denmark")) + " .highlighted_row", {
hidden: true,
});
- await page.waitForSelector((await get_stream_li(page, "Venice")) + ".highlighted_row", {
+ await page.waitForSelector((await get_stream_li(page, "Venice")) + " .highlighted_row", {
hidden: true,
});
- await page.waitForSelector((await get_stream_li(page, "Zulip")) + ".highlighted_row", {
+ await page.waitForSelector((await get_stream_li(page, "Zulip")) + " .highlighted_row", {
hidden: true,
});
await test_search_venice(page);
diff --git a/web/src/hotkey.js b/web/src/hotkey.js
index 882ef959177..14eb6c87d4d 100644
--- a/web/src/hotkey.js
+++ b/web/src/hotkey.js
@@ -1131,7 +1131,7 @@ export function process_hotkey(e, hotkey) {
} else if (stream_list.is_zoomed_in()) {
sidebar_ui.focus_topic_search_filter();
} else {
- stream_list.initiate_search();
+ sidebar_ui.initiate_search();
}
return true;
case "query_users":
diff --git a/web/src/left_sidebar_navigation_area.ts b/web/src/left_sidebar_navigation_area.ts
index ba1d98ae5b5..f71c3d92ee9 100644
--- a/web/src/left_sidebar_navigation_area.ts
+++ b/web/src/left_sidebar_navigation_area.ts
@@ -23,7 +23,7 @@ const STATES = {
CONDENSED: "condensed",
};
-function restore_views_state(): void {
+export function restore_views_state(): void {
if (page_params.is_spectator) {
// Spectators should always see the expanded view.
return;
diff --git a/web/src/pm_list.ts b/web/src/pm_list.ts
index c5f04667df6..7ea66d57b73 100644
--- a/web/src/pm_list.ts
+++ b/web/src/pm_list.ts
@@ -5,6 +5,7 @@ import * as z from "zod/mini";
import type {Filter} from "./filter.ts";
import {localstorage} from "./localstorage.ts";
import * as pm_list_data from "./pm_list_data.ts";
+import type {DisplayObject} from "./pm_list_data.ts";
import * as pm_list_dom from "./pm_list_dom.ts";
import type {PMNode} from "./pm_list_dom.ts";
import * as resize from "./resize.ts";
@@ -42,26 +43,21 @@ export function set_count(count: number): void {
export function close(): void {
private_messages_collapsed = true;
ls.set(ls_key, private_messages_collapsed);
- $("#toggle-direct-messages-section-icon").removeClass("rotate-icon-down");
- $("#toggle-direct-messages-section-icon").addClass("rotate-icon-right");
-
update_private_messages();
}
-export function _build_direct_messages_list(): vdom.Tag<PMNode> {
- const $filter = $<HTMLInputElement>(".direct-messages-list-filter").expectOne();
- const search_term = $filter.val()!;
- const conversations = pm_list_data.get_conversations(search_term);
- const pm_list_info = pm_list_data.get_list_info(zoomed, search_term);
- const conversations_to_be_shown = pm_list_info.conversations_to_be_shown;
- const more_conversations_unread_count = pm_list_info.more_conversations_unread_count;
-
- const pm_list_nodes = conversations_to_be_shown.map((conversation) =>
+export function _build_direct_messages_list(opts: {
+ all_conversations_shown: boolean;
+ conversations_to_be_shown: DisplayObject[];
+ search_term: string;
+}): vdom.Tag<PMNode> {
+ const pm_list_nodes = opts.conversations_to_be_shown.map((conversation) =>
pm_list_dom.keyed_pm_li(conversation),
);
+ const pm_list_info = pm_list_data.get_list_info(zoomed, opts.search_term);
+ const more_conversations_unread_count = pm_list_info.more_conversations_unread_count;
- const all_conversations_shown = conversations_to_be_shown.length === conversations.length;
- if (!all_conversations_shown) {
+ if (!opts.all_conversations_shown) {
pm_list_nodes.push(
pm_list_dom.more_private_conversations_li(more_conversations_unread_count),
);
@@ -86,13 +82,48 @@ function set_dom_to(new_dom: vdom.Tag<PMNode>): void {
prior_dom = new_dom;
}
-export function update_private_messages(): void {
- if (private_messages_collapsed) {
+export function update_private_messages(is_left_sidebar_search_active = false): void {
+ const is_dm_section_expanded = is_left_sidebar_search_active || !private_messages_collapsed;
+ $("#toggle-direct-messages-section-icon").toggleClass(
+ "rotate-icon-down",
+ is_dm_section_expanded,
+ );
+ $("#toggle-direct-messages-section-icon").toggleClass(
+ "rotate-icon-right",
+ !is_dm_section_expanded,
+ );
+
+ let search_term = "";
+ if (zoomed) {
+ const $filter = $<HTMLInputElement>(".direct-messages-list-filter").expectOne();
+ search_term = $filter.val()!;
+ } else {
+ search_term = ui_util.get_left_sidebar_search_term();
+ }
+ const conversations = pm_list_data.get_conversations(search_term);
+ const pm_list_info = pm_list_data.get_list_info(zoomed, search_term);
+ const conversations_to_be_shown = pm_list_info.conversations_to_be_shown;
+
+ const all_conversations_shown = conversations_to_be_shown.length === conversations.length;
+ const is_header_visible =
+ // Always show header when zoomed in.
+ zoomed ||
+ // Show header if there are conversations to be shown.
+ conversations_to_be_shown.length > 0 ||
+ // Show header if there are hidden conversations somehow.
+ !all_conversations_shown ||
+ // If there is no search term, always show the header.
+ !search_term;
+ $("#direct-messages-section-header").toggleClass("hidden-by-filters", !is_header_visible);
+
+ if (!is_dm_section_expanded) {
// In the collapsed state, we will still display the current
// conversation, to preserve the UI invariant that there's
// always something highlighted in the left sidebar.
- const conversations = pm_list_data.get_conversations();
- const active_conversation = conversations.find((conversation) => conversation.is_active);
+ const all_conversations = pm_list_data.get_conversations();
+ const active_conversation = all_conversations.find(
+ (conversation) => conversation.is_active,
+ );
if (active_conversation) {
const node = [pm_list_dom.keyed_pm_li(active_conversation)];
@@ -104,7 +135,11 @@ export function update_private_messages(): void {
prior_dom = undefined;
}
} else {
- const new_dom = _build_direct_messages_list();
+ const new_dom = _build_direct_messages_list({
+ all_conversations_shown,
+ conversations_to_be_shown,
+ search_term,
+ });
set_dom_to(new_dom);
}
// Make sure to update the left sidebar heights after updating
@@ -115,9 +150,6 @@ export function update_private_messages(): void {
export function expand(): void {
private_messages_collapsed = false;
ls.set(ls_key, private_messages_collapsed);
-
- $("#toggle-direct-messages-section-icon").addClass("rotate-icon-down");
- $("#toggle-direct-messages-section-icon").removeClass("rotate-icon-right");
update_private_messages();
}
@@ -207,6 +239,7 @@ export function toggle_private_messages_section(): void {
function zoom_in(): void {
zoomed = true;
+ ui_util.disable_left_sidebar_search();
update_private_messages();
$(".direct-messages-container").removeClass("zoom-out").addClass("zoom-in");
$("#hide-more-direct-messages").addClass("dm-zoomed-in");
@@ -219,6 +252,7 @@ function zoom_in(): void {
function zoom_out(): void {
zoomed = false;
+ ui_util.enable_left_sidebar_search();
clear_search();
$(".direct-messages-container").removeClass("zoom-in").addClass("zoom-out");
$("#hide-more-direct-messages").removeClass("dm-zoomed-in");
diff --git a/web/src/pm_list_data.ts b/web/src/pm_list_data.ts
index be06d02924d..c6664a52a73 100644
--- a/web/src/pm_list_data.ts
+++ b/web/src/pm_list_data.ts
@@ -35,7 +35,7 @@ export function get_active_user_ids_string(): string | undefined {
return people.sorted_other_user_ids(users_ids_array).join(",");
}
-type DisplayObject = {
+export type DisplayObject = {
recipients: string;
user_ids_string: string;
is_current_user: boolean;
diff --git a/web/src/resize.ts b/web/src/resize.ts
index 01693b2517f..a5371ef8366 100644
--- a/web/src/resize.ts
+++ b/web/src/resize.ts
@@ -24,8 +24,8 @@ function get_new_heights(): {
let stream_filters_max_height =
viewport_height -
Number.parseInt($("#left-sidebar").css("paddingTop"), 10) -
- ($("#left-sidebar-navigation-area").outerHeight(true) ?? 0) -
- ($("#direct-messages-section-header").outerHeight(true) ?? 0) -
+ ($("#left-sidebar-navigation-area").not(".hidden-by-filters").outerHeight(true) ?? 0) -
+ ($("#direct-messages-section-header").not(".hidden-by-filters").outerHeight(true) ?? 0) -
GAP;
// Don't let us crush the stream sidebar completely out of view
diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.js
index 2a125b877e2..9ce960dc17e 100644
--- a/web/src/server_events_dispatch.js
+++ b/web/src/server_events_dispatch.js
@@ -1016,7 +1016,7 @@ export function dispatch_normal_event(event) {
starred_messages_ui.rerender_ui();
}
if (event.property === "web_left_sidebar_unreads_count_summary") {
- sidebar_ui.update_unread_counts_visibility();
+ stream_list.update_unread_counts_visibility();
}
if (event.property === "web_left_sidebar_show_channel_folders") {
stream_list.build_stream_list(true);
diff --git a/web/src/sidebar_ui.ts b/web/src/sidebar_ui.ts
index 92f6b9aea7a..243121b034a 100644
--- a/web/src/sidebar_ui.ts
+++ b/web/src/sidebar_ui.ts
@@ -1,4 +1,5 @@
import $ from "jquery";
+import _ from "lodash";
import render_left_sidebar from "../templates/left_sidebar.hbs";
import render_buddy_list_popover from "../templates/popovers/buddy_list_popover.hbs";
@@ -7,22 +8,31 @@ import render_right_sidebar from "../templates/right_sidebar.hbs";
import {buddy_list} from "./buddy_list.ts";
import * as channel from "./channel.ts";
import * as compose_ui from "./compose_ui.ts";
+import * as keydown_util from "./keydown_util.ts";
import * as left_sidebar_navigation_area from "./left_sidebar_navigation_area.ts";
+import {ListCursor} from "./list_cursor.ts";
import {localstorage} from "./localstorage.ts";
import * as message_lists from "./message_lists.ts";
+import * as message_reminder from "./message_reminder.ts";
import * as message_viewport from "./message_viewport.ts";
import {page_params} from "./page_params.ts";
+import * as pm_list from "./pm_list.ts";
import * as popover_menus from "./popover_menus.ts";
import * as popovers from "./popovers.ts";
import * as resize from "./resize.ts";
+import * as scheduled_messages from "./scheduled_messages.ts";
+import * as search_util from "./search_util.ts";
import * as settings_config from "./settings_config.ts";
import * as settings_data from "./settings_data.ts";
import * as settings_preferences from "./settings_preferences.ts";
import * as spectators from "./spectators.ts";
import {current_user} from "./state_data.ts";
+import * as stream_list from "./stream_list.ts";
import * as ui_util from "./ui_util.ts";
import {user_settings} from "./user_settings.ts";
+export let left_sidebar_cursor: ListCursor<JQuery>;
+
function save_sidebar_toggle_status(): void {
const ls = localstorage();
ls.set("left-sidebar", $("body").hasClass("hide-left-sidebar"));
@@ -131,16 +141,6 @@ export function update_invite_user_option(): void {
}
}
-export function update_unread_counts_visibility(): void {
- const hidden = !user_settings.web_left_sidebar_unreads_count_summary;
- $(".top_left_row, #left-sidebar-navigation-list-condensed").toggleClass(
- "hide-unread-messages-count",
- hidden,
- );
- // Note: Channel folder count visibilities are handled in
- // `update_section_unread_count`, since they depend on unread counts.
-}
-
export function hide_all(): void {
hide_streamlist_sidebar();
hide_userlist_sidebar();
@@ -290,6 +290,40 @@ export function initialize(): void {
);
}
+export function update_expanded_views_for_search(search_value: string): void {
+ if (!search_value) {
+ // Show all the views if there is no search term.
+ $("#left-sidebar-navigation-area, #left-sidebar-navigation-list .top_left_row").removeClass(
+ "hidden-by-filters",
+ );
+ left_sidebar_navigation_area.update_scheduled_messages_row();
+ left_sidebar_navigation_area.update_reminders_row();
+ return;
+ }
+
+ let any_view_visible = false;
+ const expanded_views = left_sidebar_navigation_area.get_built_in_views();
+ for (const view of expanded_views) {
+ let show_view = search_util.vanilla_match({
+ val: view.name,
+ search_terms: search_util.get_search_terms(search_value),
+ });
+ const $view = $(`.top_left_${view.css_class_suffix}`);
+
+ if (show_view && $view.hasClass("top_left_scheduled_messages")) {
+ show_view = scheduled_messages.get_count() !== 0;
+ }
+
+ if (show_view && $view.hasClass("top_left_reminders")) {
+ show_view = message_reminder.get_count() !== 0;
+ }
+ $view.toggleClass("hidden-by-filters", !show_view);
+ any_view_visible ||= show_view;
+ }
+ // Hide "VIEWS" header if all views are hidden.
+ $("#left-sidebar-navigation-area").toggleClass("hidden-by-filters", !any_view_visible);
+}
+
export function initialize_left_sidebar(): void {
const primary_condensed_views =
left_sidebar_navigation_area.get_built_in_primary_condensed_views();
@@ -312,7 +346,9 @@ export function initialize_left_sidebar(): void {
$("#left-sidebar-container").html(rendered_sidebar);
// make sure home-view and left_sidebar order persists
left_sidebar_navigation_area.reorder_left_sidebar_navigation_list(user_settings.web_home_view);
- update_unread_counts_visibility();
+ stream_list.update_unread_counts_visibility();
+ initialize_left_sidebar_cursor();
+ set_event_handlers();
}
export function focus_topic_search_filter(): void {
@@ -429,9 +465,180 @@ export function initialize_right_sidebar(): void {
);
}
+function all_rows(): JQuery {
+ // This function returns all the rows in the left sidebar.
+ // It is used to find the first key for the ListCursor.
+ let $all_rows = $(".top_left_row, .bottom_left_row").not(".hidden-by-filters");
+ // Remove rows hidden due to being inactive or muted.
+ const $inactive_or_muted_rows = $(
+ "#streams_list .stream-list-section-container:not(.showing-inactive-or-muted)" +
+ " .inactive-or-muted-in-channel-folder .bottom_left_row:not(.hidden-by-filters)",
+ );
+ $all_rows = $all_rows.not($inactive_or_muted_rows);
+ return $all_rows;
+}
+
+class LeftSidebarListCursor extends ListCursor<JQuery> {
+ override adjust_scroll($li: JQuery): void {
+ $li[0]!.scrollIntoView({
+ block: "center",
+ });
+ }
+}
+
+export function initialize_left_sidebar_cursor(): void {
+ left_sidebar_cursor = new LeftSidebarListCursor({
+ list: {
+ // `scroll_container_selector` is not used
+ // since we override `adjust_scroll` above.
+ scroll_container_selector: "#left-sidebar",
+ find_li(opts) {
+ return opts.key;
+ },
+ first_key(): JQuery | undefined {
+ const $all_rows = all_rows();
+ if ($all_rows.length === 0) {
+ return undefined;
+ }
+ return $all_rows.first();
+ },
+ next_key($key) {
+ const $all_rows = all_rows();
+ if ($all_rows.length === 0) {
+ return undefined;
+ }
+
+ const key_index = $all_rows.index($key);
+ if (key_index === -1 || key_index === $all_rows.length - 1) {
+ return $key;
+ }
+ const $next = $all_rows.eq(key_index + 1);
+ return $next;
+ },
+ prev_key($key) {
+ const $all_rows = all_rows();
+ if ($all_rows.length === 0) {
+ return undefined;
+ }
+
+ const key_index = $all_rows.index($key);
+ if (key_index <= 0) {
+ return $key;
+ }
+ const $prev = $all_rows.eq(key_index - 1);
+ return $prev;
+ },
+ },
+ highlight_class: "highlighted_row",
+ });
+}
+
+function actually_update_left_sidebar_for_search(): void {
+ const search_value = ui_util.get_left_sidebar_search_term();
+ const is_left_sidebar_search_active = search_value !== "";
+
+ // Update left sidebar navigation area.
+ update_expanded_views_for_search(search_value);
+ const $views_label_container = $("#views-label-container");
+ const $views_label_icon = $("#toggle-top-left-navigation-area-icon");
+ if (
+ !$views_label_container.hasClass("showing-expanded-navigation") &&
+ is_left_sidebar_search_active
+ ) {
+ left_sidebar_navigation_area.expand_views($views_label_container, $views_label_icon);
+ } else if (!is_left_sidebar_search_active) {
+ left_sidebar_navigation_area.restore_views_state();
+ }
+
+ // Update left sidebar DM list.
+ pm_list.update_private_messages(is_left_sidebar_search_active);
+
+ // Update left sidebar channel list.
+ stream_list.update_streams_sidebar();
+
+ resize.resize_page_components();
+ left_sidebar_cursor.reset();
+ $("#left-sidebar-empty-list-message").toggleClass(
+ "hidden",
+ !is_left_sidebar_search_active || all_rows().length > 0,
+ );
+}
+
+const update_left_sidebar_for_search = _.throttle(actually_update_left_sidebar_for_search, 50);
+
+function focus_left_sidebar_filter(e: JQuery.ClickEvent): void {
+ left_sidebar_cursor.reset();
+ e.stopPropagation();
+}
+
export function focus_pm_search_filter(): void {
popovers.hide_all();
show_left_sidebar();
const $filter = $(".direct-messages-list-filter").expectOne();
$filter.trigger("focus");
}
+
+export function set_event_handlers(): void {
+ const $search_input = $(".left-sidebar-search-input").expectOne();
+
+ function keydown_enter_key(): void {
+ const row = left_sidebar_cursor.get_key();
+
+ if (row === undefined) {
+ // This can happen for empty searches, no need to warn.
+ return;
+ }
+
+ if ($(row).hasClass("stream-list-toggle-inactive-or-muted-channels")) {
+ $(row).trigger("click");
+ return;
+ }
+ const $nearest_link = $(row).find("a").first();
+ if ($nearest_link.length > 0) {
+ // If the row has a link, we click it.
+ $nearest_link[0]!.click();
+ } else {
+ // If the row does not have a link,
+ // let the browser handle it or add special
+ // handling logic for it here.
+ }
+ $search_input.val("");
+ $search_input.trigger("input");
+ $search_input.trigger("blur");
+ }
+
+ keydown_util.handle({
+ $elem: $search_input,
+ handlers: {
+ Enter() {
+ keydown_enter_key();
+ return true;
+ },
+ ArrowUp() {
+ left_sidebar_cursor.prev();
+ return true;
+ },
+ ArrowDown() {
+ left_sidebar_cursor.next();
+ return true;
+ },
+ },
+ });
+
+ $search_input.on("click", focus_left_sidebar_filter);
+ $search_input.on("focusout", () => {
+ left_sidebar_cursor.clear();
+ });
+ $search_input.on("input", update_left_sidebar_for_search);
+}
+
+export function initiate_search(): void {
+ popovers.hide_all();
+
+ const $filter = $(".left-sidebar-search-input").expectOne();
+
+ show_left_sidebar();
+ $filter.trigger("focus");
+
+ left_sidebar_cursor.reset();
+}
diff --git a/web/src/stream_list.ts b/web/src/stream_list.ts
index 78d1c3848fe..34773239f1b 100644
--- a/web/src/stream_list.ts
+++ b/web/src/stream_list.ts
@@ -1,5 +1,4 @@
import $ from "jquery";
-import _ from "lodash";
import assert from "minimalistic-assert";
import * as tippy from "tippy.js";
@@ -18,20 +17,16 @@ import * as channel_folders from "./channel_folders.ts";
import * as compose_actions from "./compose_actions.ts";
import type {Filter} from "./filter.ts";
import * as hash_util from "./hash_util.ts";
-import * as keydown_util from "./keydown_util.ts";
import * as left_sidebar_navigation_area from "./left_sidebar_navigation_area.ts";
-import {ListCursor} from "./list_cursor.ts";
import * as narrow_state from "./narrow_state.ts";
import * as pm_list from "./pm_list.ts";
import * as popovers from "./popovers.ts";
-import * as resize from "./resize.ts";
import * as scroll_util from "./scroll_util.ts";
import {web_channel_default_view_values} from "./settings_config.ts";
import * as settings_data from "./settings_data.ts";
-import * as sidebar_ui from "./sidebar_ui.ts";
import * as stream_data from "./stream_data.ts";
import * as stream_list_sort from "./stream_list_sort.ts";
-import type {StreamListRow, StreamListSection} from "./stream_list_sort.ts";
+import type {StreamListSection} from "./stream_list_sort.ts";
import * as stream_topic_history from "./stream_topic_history.ts";
import * as stream_topic_history_util from "./stream_topic_history_util.ts";
import * as sub_store from "./sub_store.ts";
@@ -53,12 +48,6 @@ export function set_update_inbox_channel_view_callback(value: (channel_id: numbe
update_inbox_channel_view_callback = value;
}
-export let stream_cursor: ListCursor<StreamListRow>;
-
-export function rewire_stream_cursor(value: typeof stream_cursor): void {
- stream_cursor = value;
-}
-
let has_scrolled = false;
const collapsed_sections = new Set<string>();
@@ -285,6 +274,16 @@ function get_section_channel_plus_icon_url(section: StreamListSection): string |
return undefined;
}
+export function update_unread_counts_visibility(): void {
+ const hidden = !user_settings.web_left_sidebar_unreads_count_summary;
+ $(".top_left_row, #left-sidebar-navigation-list-condensed").toggleClass(
+ "hide-unread-messages-count",
+ hidden,
+ );
+ // Note: Channel folder count visibilities are handled in
+ // `update_section_unread_count`, since they depend on unread counts.
+}
+
export function build_stream_list(force_rerender: boolean): void {
// The stream list in the left sidebar contains 3 sections:
// pinned, normal, and dormant streams, with headings above them
@@ -358,8 +357,9 @@ export function build_stream_list(force_rerender: boolean): void {
left_sidebar_navigation_area.update_dom_with_unread_counts(counts, false);
update_dom_with_unread_counts(counts);
update_stream_section_mention_indicators();
- sidebar_ui.update_unread_counts_visibility();
+ update_unread_counts_visibility();
set_sections_states();
+ // Show inactive channels when user starts typing.
$("#streams_list").toggleClass("is_searching", ui_util.get_left_sidebar_search_term() !== "");
}
@@ -457,13 +457,16 @@ function toggle_section_collapse($container: JQuery): void {
}
function set_sections_states(): void {
- for (const section_id of collapsed_sections) {
- const $container = $(`#stream-list-${section_id}-container`);
- $container.toggleClass("collapsed", true);
- $container
- .find(".stream-list-section-toggle")
- .toggleClass("rotate-icon-down", false)
- .toggleClass("rotate-icon-right", true);
+ if (ui_util.get_left_sidebar_search_term() === "") {
+ // Restore the collapsed state of sections.
+ for (const section_id of collapsed_sections) {
+ const $container = $(`#stream-list-${section_id}-container`);
+ $container.toggleClass("collapsed", true);
+ $container
+ .find(".stream-list-section-toggle")
+ .toggleClass("rotate-icon-down", false)
+ .toggleClass("rotate-icon-right", true);
+ }
}
for (const section_id of sections_showing_inactive_or_muted) {
$(`#stream-list-${section_id}-container`).toggleClass("showing-inactive-or-muted", true);
@@ -705,8 +708,6 @@ export let update_streams_sidebar = (force_rerender = false): void => {
build_stream_list(force_rerender);
- stream_cursor.redraw();
-
const filter = narrow_state.filter();
if (!filter) {
return;
@@ -1038,56 +1039,6 @@ export function handle_message_view_deactivated(): void {
clear_topics();
}
-function focus_stream_filter(e: JQuery.ClickEvent): void {
- stream_cursor.reset();
- e.stopPropagation();
-}
-
-function actually_update_streams_for_search(): void {
- update_streams_sidebar();
- resize.resize_page_components();
- stream_cursor.reset();
-}
-
-const update_streams_for_search = _.throttle(actually_update_streams_for_search, 50);
-
-// Exported for tests only.
-export function initialize_stream_cursor(): void {
- stream_cursor = new ListCursor<StreamListRow>({
- list: {
- scroll_container_selector: "#left_sidebar_scroll_container",
- find_li(opts) {
- switch (opts.key.type) {
- case "stream":
- return get_stream_li(opts.key.stream_id);
- case "inactive_or_muted_toggle":
- return $(
- `#stream-list-${opts.key.section_id}-container .stream-list-toggle-inactive-or-muted-channels`,
- );
- default:
- throw new Error("Unexpected key type");
- }
- },
- first_key: stream_list_sort.first_row,
- prev_key: (row) =>
- stream_list_sort.prev_row(
- row,
- sections_showing_inactive_or_muted,
- collapsed_sections,
- topic_list.active_stream_id(),
- ),
- next_key: (row) =>
- stream_list_sort.next_row(
- row,
- sections_showing_inactive_or_muted,
- collapsed_sections,
- topic_list.active_stream_id(),
- ),
- },
- highlight_class: "highlighted_row",
- });
-}
-
export function initialize({
show_channel_feed,
update_inbox_channel_view,
@@ -1102,7 +1053,6 @@ export function initialize({
// when new messages come in, but it's fairly quick.
build_stream_list(false);
update_subscribe_to_more_streams_link();
- initialize_stream_cursor();
initialize_tippy_tooltips();
set_event_handlers({show_channel_feed});
@@ -1166,7 +1116,7 @@ export function initialize_tippy_tooltips(): void {
});
}
-function on_sidebar_channel_click(
+export function on_sidebar_channel_click(
stream_id: number,
// Null is used when this is called via `Enter`, because the
// keyboard abstraction we're using doesn't need to pass on the event.
@@ -1337,52 +1287,6 @@ export function set_event_handlers({
toggle_pm_header_icon();
});
- const $search_input = $(".left-sidebar-search-input").expectOne();
-
- function keydown_enter_key(): void {
- const row = stream_cursor.get_key();
-
- if (row === undefined) {
- // This can happen for empty searches, no need to warn.
- return;
- }
-
- switch (row.type) {
- case "stream":
- on_sidebar_channel_click(row.stream_id, null, show_channel_feed);
- break;
- case "inactive_or_muted_toggle":
- toggle_inactive_or_muted_channels($(`#stream-list-${row.section_id}-container`));
- break;
- default:
- throw new Error("Unexpected key type");
- }
- }
-
- keydown_util.handle({
- $elem: $search_input,
- handlers: {
- Enter() {
- keydown_enter_key();
- return true;
- },
- ArrowUp() {
- stream_cursor.prev();
- return true;
- },
- ArrowDown() {
- stream_cursor.next();
- return true;
- },
- },
- });
-
- $search_input.on("click", focus_stream_filter);
- $search_input.on("focusout", () => {
- stream_cursor.clear();
- });
- $search_input.on("input", update_streams_for_search);
-
$("#streams_list").on(
"click",
".stream-list-section-container .stream-list-subsection-header",
@@ -1429,31 +1333,12 @@ export function searching(): boolean {
return $(".left-sidebar-search-input").expectOne().is(":focus");
}
-export function test_clear_search(): void {
- const $filter = $(".left-sidebar-search-input").expectOne();
- $filter.val("");
- $filter.trigger("blur");
- update_streams_for_search();
-}
-
-export function initiate_search(): void {
- popovers.hide_all();
-
- const $filter = $(".left-sidebar-search-input").expectOne();
-
- sidebar_ui.show_left_sidebar();
- $filter.trigger("focus");
-
- stream_cursor.reset();
-}
-
export function clear_search(): void {
const $filter = $(".left-sidebar-search-input").expectOne();
if ($filter.val() !== "") {
$filter.val("");
- update_streams_for_search();
+ $filter.trigger("input");
}
- stream_cursor.clear();
$filter.trigger("blur");
}
diff --git a/web/src/stream_list_sort.ts b/web/src/stream_list_sort.ts
index 16b3cf49eeb..c5627e9dd5b 100644
--- a/web/src/stream_list_sort.ts
+++ b/web/src/stream_list_sort.ts
@@ -2,10 +2,12 @@ import assert from "minimalistic-assert";
import * as channel_folders from "./channel_folders.ts";
import {$t} from "./i18n.ts";
+import * as narrow_state from "./narrow_state.ts";
import * as settings_config from "./settings_config.ts";
import * as stream_data from "./stream_data.ts";
import * as sub_store from "./sub_store.ts";
import type {StreamSubscription} from "./sub_store.ts";
+import * as topic_list_data from "./topic_list_data.ts";
import {user_settings} from "./user_settings.ts";
import * as util from "./util.ts";
@@ -131,6 +133,20 @@ export function sort_groups(stream_ids: number[], search_term: string): StreamLi
word_separator_regex,
);
+ const current_channel_id = narrow_state.stream_id(narrow_state.filter(), true);
+ if (
+ current_channel_id !== undefined &&
+ stream_data.is_subscribed(current_channel_id) &&
+ !stream_ids.includes(current_channel_id) &&
+ // If any of the topics of the channel match the search term, we need to
+ // include the channel in the list of streams.
+ topic_list_data.get_list_info(current_channel_id, false, (topic_names) =>
+ topic_list_data.filter_topics_by_search_term(topic_names, search_term),
+ ).items.length > 0
+ ) {
+ stream_ids.push(current_channel_id);
+ }
+
const pinned_section: StreamListSection = {
id: "pinned-streams",
folder_id: null,
diff --git a/web/src/topic_list.ts b/web/src/topic_list.ts
index a8b5c53aab4..ba8ef0b177b 100644
--- a/web/src/topic_list.ts
+++ b/web/src/topic_list.ts
@@ -21,6 +21,7 @@ import type {TopicFilterPill, TopicFilterPillWidget} from "./topic_filter_pill.t
import * as topic_list_data from "./topic_list_data.ts";
import type {TopicInfo} from "./topic_list_data.ts";
import * as typeahead_helper from "./typeahead_helper.ts";
+import * as ui_util from "./ui_util.ts";
import * as vdom from "./vdom.ts";
/* Track all active widgets with a Map by stream_id. We have at max
@@ -65,6 +66,7 @@ export function close(): void {
export function zoom_out(): void {
zoomed = false;
+ ui_util.enable_left_sidebar_search();
const stream_ids = [...active_widgets.keys()];
@@ -427,6 +429,7 @@ export function left_sidebar_scroll_zoomed_in_topic_into_view(): void {
// handle hiding/showing the non-narrowed streams
export function zoom_in(): void {
zoomed = true;
+ ui_util.disable_left_sidebar_search();
const stream_id = active_stream_id();
if (stream_id === undefined) {
@@ -470,7 +473,10 @@ export function zoom_in(): void {
}
export function get_left_sidebar_topic_search_term(): string {
- return $("#topic_filter_query").text().trim();
+ if (zoomed) {
+ return $("#topic_filter_query").text().trim();
+ }
+ return ui_util.get_left_sidebar_search_term();
}
export function get_typeahead_search_pills_syntax(): string {
diff --git a/web/src/topic_list_data.ts b/web/src/topic_list_data.ts
index 493a137be96..6598c796ae3 100644
--- a/web/src/topic_list_data.ts
+++ b/web/src/topic_list_data.ts
@@ -214,9 +214,7 @@ export function get_list_info(
topic_names.unshift(narrowed_topic);
}
- if (zoomed) {
- topic_names = filter_topics(topic_names);
- }
+ topic_names = filter_topics(topic_names);
if (stream_muted && !zoomed) {
const unmuted_or_followed_topics = topic_names.filter((topic) =>
diff --git a/web/src/ui_util.ts b/web/src/ui_util.ts
index 3308ffb7f43..287ef8fa152 100644
--- a/web/src/ui_util.ts
+++ b/web/src/ui_util.ts
@@ -343,3 +343,16 @@ export function get_left_sidebar_search_term(): string {
assert(search_term !== undefined);
return search_term.trim();
}
+
+export function disable_left_sidebar_search(): void {
+ if ($<HTMLInputElement>("#left-sidebar-search input").val()) {
+ // Triggle click on the close button to clear the search term and
+ // update the left sidebar.
+ $("#left-sidebar-search .input-close-filter-button").trigger("click");
+ }
+ $("#left-sidebar-search").hide();
+}
+
+export function enable_left_sidebar_search(): void {
+ $("#left-sidebar-search").show();
+}
diff --git a/web/styles/left_sidebar.css b/web/styles/left_sidebar.css
index fcbb9b14009..dbc8718e549 100644
--- a/web/styles/left_sidebar.css
+++ b/web/styles/left_sidebar.css
@@ -714,6 +714,12 @@
}
}
+.highlighted_row.top_left_row,
+.highlighted_row.bottom_left_row {
+ outline: 2px solid var(--color-outline-focus);
+ outline-offset: -2px;
+}
+
#stream_filters
.narrow-filter
.topic-list
@@ -2152,3 +2158,8 @@ li.topic-list-item {
.top_left_row.hidden-by-filters {
display: none !important;
}
+
+#left-sidebar-navigation-area.hidden-by-filters,
+#direct-messages-section-header.hidden-by-filters {
+ display: none;
+}
diff --git a/web/styles/right_sidebar.css b/web/styles/right_sidebar.css
index 9d3927b933a..cd00c467798 100644
--- a/web/styles/right_sidebar.css
+++ b/web/styles/right_sidebar.css
@@ -207,23 +207,6 @@
}
}
- .empty-list-message {
- font-style: italic;
- color: var(--color-text-empty-list-message);
- /* Overwrite default empty list font size, to look better under the subheaders. */
- /* 14px at 16px/1em */
- font-size: 0.875em;
- /* Override .empty-list-message !important styling */
- padding: 0 !important;
- text-align: left;
-
- &:hover {
- /* Prevent hover styles set on other rows. */
- box-shadow: none;
- background-color: inherit;
- }
- }
-
/* Overwrite some stray list rules (including one in left_sidebar.css) to turn color
back to the bootstrap default. */
.view-all-subscribers-link,
@@ -241,6 +224,30 @@
}
}
+#left-sidebar-empty-list-message {
+ list-style-type: none;
+ padding-top: 10px;
+ text-align: center;
+}
+
+#left-sidebar-empty-list-message .empty-list-message,
+.buddy-list-section .empty-list-message {
+ font-style: italic;
+ color: var(--color-text-empty-list-message);
+ /* Overwrite default empty list font size, to look better under the subheaders. */
+ /* 14px at 16px/1em */
+ font-size: 0.875em;
+ /* Override .empty-list-message !important styling */
+ padding: 0 !important;
+ text-align: left;
+
+ &:hover {
+ /* Prevent hover styles set on other rows. */
+ box-shadow: none;
+ background-color: inherit;
+ }
+}
+
.buddy-list-subsection-header {
display: grid;
align-items: center;
diff --git a/web/templates/left_sidebar.hbs b/web/templates/left_sidebar.hbs
index 07da692d5de..9a279bed2d6 100644
--- a/web/templates/left_sidebar.hbs
+++ b/web/templates/left_sidebar.hbs
@@ -7,6 +7,11 @@
<i id="streams_inline_icon" class="add_stream_icon zulip-icon zulip-icon-square-plus" aria-hidden="true" ></i>
</span>
</div>
+ <ul id="left-sidebar-empty-list-message" class="hidden">
+ {{> empty_list_widget_for_list
+ empty_list_message=(t "No matches.")
+ }}
+ </ul>
<div id="left-sidebar-navigation-area" class="left-sidebar-navigation-area">
<div id="views-label-container" class="showing-expanded-navigation{{#if is_spectator}} remove-pointer-for-spectator{{/if}}">
<i id="toggle-top-left-navigation-area-icon" class="zulip-icon zulip-icon-heading-triangle-right sidebar-heading-icon rotate-icon-down views-tooltip-target hidden-for-spectators" aria-hidden="true" tabindex="0" role="button"></i>
@@ -25,9 +30,7 @@
</div>
</div>
<ul id="left-sidebar-navigation-list" class="left-sidebar-navigation-list filters">
- {{#each expanded_views}}
- {{> left_sidebar_expanded_view_item . }}
- {{/each}}
+ {{> left_sidebar_expanded_view_items_list expanded_views=expanded_views}}
</ul>
</div>
diff --git a/web/templates/left_sidebar_expanded_view_item.hbs b/web/templates/left_sidebar_expanded_view_item.hbs
index e204f5d5666..3d9b09c9a20 100644
--- a/web/templates/left_sidebar_expanded_view_item.hbs
+++ b/web/templates/left_sidebar_expanded_view_item.hbs
@@ -5,7 +5,11 @@
</span>
{{~!-- squash whitespace --~}}
<span class="left-sidebar-navigation-label">{{name}}</span>
- <span class="unread_count {{unread_count_type}}"></span>
+ <span class="unread_count {{unread_count_type}}{{#unless unread_count}} hide{{/unless}}">
+ {{#if unread_count}}
+ {{unread_count}}
+ {{/if}}
+ </span>
{{#if supports_masked_unread}}
<span class="masked_unread_count">
<i class="zulip-icon zulip-icon-masked-unread"></i>
diff --git a/web/templates/left_sidebar_expanded_view_items_list.hbs b/web/templates/left_sidebar_expanded_view_items_list.hbs
new file mode 100644
index 00000000000..d63a843036e
--- /dev/null
+++ b/web/templates/left_sidebar_expanded_view_items_list.hbs
@@ -0,0 +1,3 @@
+{{#each expanded_views}}
+ {{> left_sidebar_expanded_view_item . }}
+{{/each}}
diff --git a/web/tests/dispatch.test.cjs b/web/tests/dispatch.test.cjs
index 29281f49397..b9ecef0c7ba 100644
--- a/web/tests/dispatch.test.cjs
+++ b/web/tests/dispatch.test.cjs
@@ -1295,7 +1295,7 @@ run_test("user_settings", ({override}) => {
assert_same(user_settings.web_left_sidebar_show_channel_folders, false);
event = event_fixtures.user_settings__web_left_sidebar_unreads_count_summary;
- override(sidebar_ui, "update_unread_counts_visibility", noop);
+ override(stream_list, "update_unread_counts_visibility", noop);
override(user_settings, "web_left_sidebar_unreads_count_summary", true);
dispatch(event);
assert_same(user_settings.web_left_sidebar_unreads_count_summary, false);
diff --git a/web/tests/hotkey.test.cjs b/web/tests/hotkey.test.cjs
index a1fbf08e1d7..4d9f61da657 100644
--- a/web/tests/hotkey.test.cjs
+++ b/web/tests/hotkey.test.cjs
@@ -86,9 +86,7 @@ const reactions = mock_esm("../src/reactions");
const read_receipts = mock_esm("../src/read_receipts");
const search = mock_esm("../src/search");
const settings_data = mock_esm("../src/settings_data");
-const stream_list = mock_esm("../src/stream_list", {
- is_zoomed_in: () => false,
-});
+const sidebar_ui = mock_esm("../src/sidebar_ui");
const stream_popover = mock_esm("../src/stream_popover");
const stream_settings_ui = mock_esm("../src/stream_settings_ui");
@@ -405,7 +403,7 @@ test_while_not_editing_text("basic mappings", () => {
assert_mapping("?", browser_history, "go_to_location");
assert_mapping("/", search, "initiate_search");
assert_mapping("w", activity_ui, "initiate_search");
- assert_mapping("q", stream_list, "initiate_search");
+ assert_mapping("q", sidebar_ui, "initiate_search");
assert_mapping("A", message_view, "stream_cycle_backward", true);
assert_mapping("D", message_view, "stream_cycle_forward", true);
diff --git a/web/tests/stream_list.test.cjs b/web/tests/stream_list.test.cjs
index 093f7d3dd41..d25ad15d8b4 100644
--- a/web/tests/stream_list.test.cjs
+++ b/web/tests/stream_list.test.cjs
@@ -21,10 +21,6 @@ let unread_unmuted_count;
let stream_has_any_unread_mentions;
const topic_list = mock_esm("../src/topic_list");
-mock_esm("../src/scroll_util", {
- scroll_element_into_container() {},
- get_scroll_element: ($element) => $element,
-});
mock_esm("../src/unread", {
unread_count_info_for_stream: () => ({
unmuted_count: unread_unmuted_count,
@@ -409,7 +405,6 @@ test_ui("zoom_in_and_zoom_out", ({mock_template}) => {
$("#stream-filters-container")[0] = {
dataset: {},
};
- stream_list.initialize_stream_cursor();
mock_template("filter_topics.hbs", false, () => "<filter-topics-stub>");
let filter_topics_appended = false;
@@ -489,26 +484,6 @@ test_ui("narrowing", ({override_rewire}) => {
assert.ok(topics_closed);
});
-test_ui("focusout_user_filter", () => {
- stream_list.set_event_handlers({show_channel_feed() {}});
- const e = {};
- const click_handler = $(".left-sidebar-search-input").get_on_handler("focusout");
- click_handler(e);
-});
-
-test_ui("focus_user_filter", () => {
- stream_list.set_event_handlers({show_channel_feed() {}});
-
- initialize_stream_data();
- stream_list.build_stream_list();
-
- const e = {
- stopPropagation() {},
- };
- const click_handler = $(".left-sidebar-search-input").get_on_handler("click");
- click_handler(e);
-});
-
test_ui("sort_streams", ({override_rewire}) => {
// TODO/channel-folders: Fix this test.
if (override_rewire !== undefined) {
diff --git a/web/tests/stream_search.test.cjs b/web/tests/stream_search.test.cjs
deleted file mode 100644
index 99094b66efc..00000000000
--- a/web/tests/stream_search.test.cjs
+++ /dev/null
@@ -1,131 +0,0 @@
-"use strict";
-
-const assert = require("node:assert/strict");
-
-const {mock_esm, zrequire} = require("./lib/namespace.cjs");
-const {run_test, noop} = require("./lib/test.cjs");
-const $ = require("./lib/zjquery.cjs");
-
-// This tests the stream searching functionality which currently
-// lives in stream_list.ts.
-
-mock_esm("../src/resize", {
- resize_page_components: noop,
-
- resize_stream_filters_container: noop,
-});
-
-const popovers = mock_esm("../src/popovers");
-const sidebar_ui = mock_esm("../src/sidebar_ui");
-
-const stream_list = zrequire("stream_list");
-
-function expand_sidebar() {
- $(".app-main .column-left").addClass("expanded");
-}
-
-function make_cursor_helper(override_rewire) {
- const events = [];
-
- override_rewire(stream_list, "stream_cursor", {
- reset() {
- events.push("reset");
- },
- clear() {
- events.push("clear");
- },
- });
-
- return {
- events,
- };
-}
-
-function clear_search_input() {
- stream_list.test_clear_search();
-}
-
-run_test("basics", ({override, override_rewire}) => {
- override(popovers, "hide_all", noop);
- override(sidebar_ui, "show_left_sidebar", noop);
-
- const $input = $(".left-sidebar-search-input");
-
- expand_sidebar();
-
- let cursor_helper = make_cursor_helper(override_rewire);
-
- function verify_focused() {
- assert.ok(stream_list.searching());
- assert.ok($input.is_focused());
- }
-
- function verify_not_focused() {
- assert.ok(!stream_list.searching());
- assert.ok(!$input.is_focused());
- }
-
- function verify_list_updated(f) {
- let updated;
- override_rewire(stream_list, "update_streams_sidebar", () => {
- updated = true;
- });
-
- f();
- assert.ok(updated);
- }
-
- // Initiate search
- stream_list.initiate_search();
- verify_focused();
-
- (function add_some_text_and_clear() {
- stream_list.initiate_search();
- cursor_helper = make_cursor_helper(override_rewire);
- $input.val("foo");
- verify_list_updated(() => {
- clear_search_input();
- });
- assert.deepEqual(cursor_helper.events, ["reset"]);
- })();
-
- // Escape a non-empty search.
- stream_list.initiate_search();
- $input.val("foo");
- stream_list.clear_search();
- verify_not_focused();
-
- // Escape an empty search.
- stream_list.initiate_search();
- $input.val("");
- stream_list.clear_search();
- verify_not_focused();
-});
-
-run_test("expanding_sidebar", ({override, override_rewire}) => {
- const cursor_helper = make_cursor_helper(override_rewire);
-
- $(".app-main .column-left").removeClass("expanded");
-
- const events = [];
-
- override(popovers, "hide_all", () => {
- events.push("popovers.hide_all");
- });
-
- override(sidebar_ui, "show_left_sidebar", () => {
- events.push("popovers.hide_all", "sidebar_ui.show_streamlist_sidebar");
- });
-
- $("#streamlist-toggle").show();
-
- stream_list.initiate_search();
-
- assert.deepEqual(events, [
- "popovers.hide_all",
- "popovers.hide_all",
- "sidebar_ui.show_streamlist_sidebar",
- ]);
-
- assert.deepEqual(cursor_helper.events, ["reset"]);
-});