Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
left-sidebar: Add expand/collapse all options to filter menu.
Nirvedh Harpald1049f38189d
diff --git a/web/src/channel_folders_popover.ts b/web/src/channel_folders_popover.tsindex b930d6e97f4..becc8eaf463 100644--- a/web/src/channel_folders_popover.ts+++ b/web/src/channel_folders_popover.ts@@ -5,7 +5,10 @@ import type * as tippy from "tippy.js";import render_channel_folder_setting_popover from "../templates/popovers/channel_folder_setting_popover.hbs";import * as channel from "./channel.ts";+import * as left_sidebar_navigation_area from "./left_sidebar_navigation_area.ts";+import * as pm_list from "./pm_list.ts";import * as popover_menus from "./popover_menus.ts";+import * as stream_list from "./stream_list.ts";import {parse_html} from "./ui_util.ts";import {user_settings} from "./user_settings.ts";@@ -33,6 +36,35 @@ function do_change_show_channel_folders_inbox(instance: tippy.Instance): void {popover_menus.hide_current_popover_if_visible(instance);}+function expand_all_sections(instance: tippy.Instance): void {+ // Expand Views section+ left_sidebar_navigation_area.force_expand_views();++ // Expand Direct Messages section+ if (pm_list.is_private_messages_collapsed()) {+ pm_list.expand();+ }++ // Expand all channel/stream sections+ stream_list.expand_all_stream_sections();++ popover_menus.hide_current_popover_if_visible(instance);+}++function collapse_all_sections(instance: tippy.Instance): void {+ // Collapse Views section+ left_sidebar_navigation_area.force_collapse_views();++ // Collapse Direct Messages section+ if (!pm_list.is_private_messages_collapsed()) {+ pm_list.close();+ }++ // Collapse all channel/stream sections+ stream_list.collapse_all_stream_sections();+ popover_menus.hide_current_popover_if_visible(instance);+}+export function initialize(): void {popover_menus.register_popover_menu("#left-sidebar-search .channel-folders-sidebar-menu-icon", {...popover_menus.left_sidebar_tippy_options,@@ -43,6 +75,12 @@ export function initialize(): void {$popper.one("click", "#left_sidebar_channel_folders", () => {do_change_show_channel_folders_left_sidebar(instance);});+ $popper.one("click", "#left_sidebar_expand_all", () => {+ expand_all_sections(instance);+ });+ $popper.one("click", "#left_sidebar_collapse_all", () => {+ collapse_all_sections(instance);+ });},onShow(instance) {const show_channel_folders = user_settings.web_left_sidebar_show_channel_folders;diff --git a/web/src/left_sidebar_navigation_area.ts b/web/src/left_sidebar_navigation_area.tsindex 690db2a5a5d..eabe1b6ba12 100644--- a/web/src/left_sidebar_navigation_area.ts+++ b/web/src/left_sidebar_navigation_area.ts@@ -150,27 +150,58 @@ export function expand_views($views_label_container: JQuery, $views_label_icon:$views_label_icon.removeClass("rotate-icon-right");}-function toggle_condensed_navigation_area(): void {+export function collapse_views($views_label_container: JQuery, $views_label_icon: JQuery): void {+ $views_label_container.addClass("showing-condensed-navigation");+ $views_label_container.removeClass("showing-expanded-navigation");+ $views_label_icon.addClass("rotate-icon-right");+ $views_label_icon.removeClass("rotate-icon-down");+}++export function force_expand_views(): void {+ if (page_params.is_spectator) {+ // We don't support collapsing VIEWS for spectators, so exit early.+ return;+ }+const $views_label_container = $("#views-label-container");const $views_label_icon = $("#toggle-top-left-navigation-area-icon");+ if ($views_label_container.hasClass("showing-condensed-navigation")) {+ expand_views($views_label_container, $views_label_icon);+ save_state(STATES.EXPANDED);+ resize.resize_stream_filters_container();+ }+}++export function force_collapse_views(): void {if (page_params.is_spectator) {// We don't support collapsing VIEWS for spectators, so exit early.return;}+ 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")) {- // Toggle into the condensed state- $views_label_container.addClass("showing-condensed-navigation");- $views_label_container.removeClass("showing-expanded-navigation");- $views_label_icon.addClass("rotate-icon-right");- $views_label_icon.removeClass("rotate-icon-down");+ collapse_views($views_label_container, $views_label_icon);save_state(STATES.CONDENSED);+ resize.resize_stream_filters_container();+ }+}++function toggle_condensed_navigation_area(): void {+ const $views_label_container = $("#views-label-container");++ if (page_params.is_spectator) {+ // We don't support collapsing VIEWS for spectators, so exit early.+ return;+ }++ if ($views_label_container.hasClass("showing-expanded-navigation")) {+ force_collapse_views();} else {- expand_views($views_label_container, $views_label_icon);- save_state(STATES.EXPANDED);+ force_expand_views();}- resize.resize_stream_filters_container();}export function animate_mention_changes($li: JQuery, new_mention_count: number): void {diff --git a/web/src/stream_list.ts b/web/src/stream_list.tsindex bad9e502c4e..e472b6829e0 100644--- a/web/src/stream_list.ts+++ b/web/src/stream_list.ts@@ -1,6 +1,7 @@import $ from "jquery";import assert from "minimalistic-assert";import * as tippy from "tippy.js";+import * as z from "zod/mini";import render_filter_topics from "../templates/filter_topics.hbs";import render_go_to_channel_feed_tooltip from "../templates/go_to_channel_feed_tooltip.hbs";@@ -19,6 +20,7 @@ import type {Filter} from "./filter.ts";import * as hash_util from "./hash_util.ts";import {$t} from "./i18n.ts";import * as left_sidebar_navigation_area from "./left_sidebar_navigation_area.ts";+import {localstorage} from "./localstorage.ts";import * as narrow_state from "./narrow_state.ts";import * as pm_list from "./pm_list.ts";import * as popovers from "./popovers.ts";@@ -54,6 +56,11 @@ let has_scrolled = false;const collapsed_sections = new Set<string>();const sections_showing_inactive_or_muted = new Set<string>();+// Persistence for collapsed sections state+const collapsed_sections_ls_key = "left_sidebar_collapsed_stream_sections";+const collapsed_sections_ls_schema = z._default(z.array(z.string()), []);+const ls = localstorage();+export function is_zoomed_in(): boolean {return zoomed_in;}@@ -490,6 +497,31 @@ function toggle_section_collapse($container: JQuery): void {collapsed_sections.delete(section_id);}maybe_hide_topic_bracket(section_id);+ save_collapsed_sections_state();+}++function save_collapsed_sections_state(): void {+ // Prune any section IDs that no longer exist (e.g., a folder was deleted+ // in another browser) before saving to localStorage.+ const valid_section_ids = new Set(stream_list_sort.section_ids());+ for (const section_id of collapsed_sections) {+ if (!valid_section_ids.has(section_id)) {+ collapsed_sections.delete(section_id);+ }+ }+ ls.set(collapsed_sections_ls_key, [...collapsed_sections]);+}++function restore_collapsed_sections_state(): void {+ // Note: This code path has no way to know whether all of the+ // sections we last saved actually exist, because we're running+ // before the stream_list_sort code path has determined that.+ // Validation happens in save_collapsed_sections_state() instead.+ const collapsed_array = collapsed_sections_ls_schema.parse(ls.get(collapsed_sections_ls_key));+ collapsed_sections.clear();+ for (const section_id of collapsed_array) {+ collapsed_sections.add(section_id);+ }}export let set_sections_states = function (): void {@@ -1102,11 +1134,15 @@ export function initialize({update_inbox_channel_view: (channel_id: number) => void;}): void {update_inbox_channel_view_callback = update_inbox_channel_view;+ restore_collapsed_sections_state();create_initial_sidebar_rows();// We build the stream_list now. It may get re-built again very shortly// when new messages come in, but it's fairly quick.build_stream_list(false);+ // After building the stream list, prune any invalid section IDs that were+ // restored from localStorage (e.g., folders that no longer exist).+ save_collapsed_sections_state();update_subscribe_to_more_streams_link();initialize_tippy_tooltips();set_event_handlers({show_channel_feed});@@ -1458,3 +1494,23 @@ export function get_current_stream_li(): JQuery | undefined {return $stream_li;}++export function expand_all_stream_sections(): void {+ for (const section_id of collapsed_sections) {+ const $container = $(`#stream-list-${section_id}-container`);+ if ($container.hasClass("collapsed")) {+ toggle_section_collapse($container);+ }+ }+}++export function collapse_all_stream_sections(): void {+ for (const section_id of stream_list_sort.section_ids()) {+ if (!collapsed_sections.has(section_id)) {+ const $container = $(`#stream-list-${section_id}-container`);+ if (!$container.hasClass("collapsed")) {+ toggle_section_collapse($container);+ }+ }+ }+}diff --git a/web/templates/popovers/channel_folder_setting_popover.hbs b/web/templates/popovers/channel_folder_setting_popover.hbsindex 931bf8efb20..b411eed7a90 100644--- a/web/templates/popovers/channel_folder_setting_popover.hbs+++ b/web/templates/popovers/channel_folder_setting_popover.hbs@@ -1,5 +1,17 @@<div class="popover-menu" data-simplebar data-simplebar-tab-index="-1"><ul role="menu" class="popover-menu-list">+ <li role="none" class="link-item popover-menu-list-item">+ <a role="menuitem" id="left_sidebar_expand_all" class="popover-menu-link" tabindex="0">+ <i class="popover-menu-icon zulip-icon zulip-icon-expand" aria-hidden="true"></i>+ <span class="popover-menu-label">{{t "Expand all sections" }}</span>+ </a>+ </li>+ <li role="none" class="link-item popover-menu-list-item">+ <a role="menuitem" id="left_sidebar_collapse_all" class="popover-menu-link" tabindex="0">+ <i class="popover-menu-icon zulip-icon zulip-icon-collapse" aria-hidden="true"></i>+ <span class="popover-menu-label">{{t "Collapse all sections" }}</span>+ </a>+ </li><li role="none" class="link-item popover-menu-list-item"><a role="menuitem" id="left_sidebar_channel_folders" class="popover-menu-link" tabindex="0"><i class="popover-menu-icon zulip-icon zulip-icon-folder" aria-hidden="true"></i>