Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
topic_list: Generalize use of TopicListWidget.
Aman Agrawalf5714a0c5507
diff --git a/web/src/stream_list.ts b/web/src/stream_list.tsindex def18d89f84..f7d690027ed 100644--- a/web/src/stream_list.ts+++ b/web/src/stream_list.ts@@ -918,7 +918,11 @@ export function set_event_handlers({let topics = stream_topic_history.get_recent_topic_names(stream_id);const navigate_to_stream = (): void => {- const topic_list_info = topic_list_data.get_list_info(stream_id, false, "");+ const topic_list_info = topic_list_data.get_list_info(+ stream_id,+ false,+ (topic_names: string[]) => topic_names,+ );const topic_item = topic_list_info.items[0];if (topic_item !== undefined) {const destination_url = hash_util.by_channel_topic_permalink(diff --git a/web/src/topic_list.ts b/web/src/topic_list.tsindex 21ce7399daa..7a51eda2707 100644--- a/web/src/topic_list.ts+++ b/web/src/topic_list.ts@@ -25,7 +25,7 @@ import * as vdom from "./vdom.ts";expanded.)*/-const active_widgets = new Map<number, TopicListWidget>();+const active_widgets = new Map<number, LeftSidebarTopicListWidget>();// We know whether we're zoomed or not.let zoomed = false;@@ -153,17 +153,23 @@ export class TopicListWidget {prior_dom: vdom.Tag<ListInfoNodeOptions> | undefined = undefined;$parent_elem: JQuery;my_stream_id: number;+ filter_topics: (topic_names: string[]) => string[];- constructor($parent_elem: JQuery, my_stream_id: number) {+ constructor(+ $parent_elem: JQuery,+ my_stream_id: number,+ filter_topics: (topic_names: string[]) => string[],+ ) {this.$parent_elem = $parent_elem;this.my_stream_id = my_stream_id;+ this.filter_topics = filter_topics;}build_list(spinner: boolean): vdom.Tag<ListInfoNodeOptions> {const list_info = topic_list_data.get_list_info(this.my_stream_id,zoomed,- get_left_sidebar_topic_search_term(),+ this.filter_topics,);const num_possible_topics = list_info.num_possible_topics;@@ -239,6 +245,17 @@ export class TopicListWidget {}}+function filter_topics_left_sidebar(topic_names: string[]): string[] {+ const search_term = get_left_sidebar_topic_search_term();+ return topic_list_data.filter_topics_by_search_term(topic_names, search_term);+}++export class LeftSidebarTopicListWidget extends TopicListWidget {+ constructor($parent_elem: JQuery, my_stream_id: number) {+ super($parent_elem, my_stream_id, filter_topics_left_sidebar);+ }+}+export function clear_topic_search(e: JQuery.Event): void {e.stopPropagation();const $input = $("#filter-topic-input");@@ -290,7 +307,7 @@ export function rebuild_left_sidebar($stream_li: JQuery, stream_id: number): voi}clear();- const widget = new TopicListWidget($stream_li, stream_id);+ const widget = new LeftSidebarTopicListWidget($stream_li, stream_id);widget.build();active_widgets.set(stream_id, widget);diff --git a/web/src/topic_list_data.ts b/web/src/topic_list_data.tsindex b46a5b5ab47..0687184ba2a 100644--- a/web/src/topic_list_data.ts+++ b/web/src/topic_list_data.ts@@ -156,7 +156,7 @@ type TopicListInfo = {more_topics_unread_count_muted: boolean;};-function filter_by_search_term(topic_names: string[], search_term: string): string[] {+export function filter_topics_by_search_term(topic_names: string[], search_term: string): string[] {if (search_term === "") {return topic_names;}@@ -174,7 +174,7 @@ function filter_by_search_term(topic_names: string[], search_term: string): striexport function get_list_info(stream_id: number,zoomed: boolean,- search_term: string,+ filter_topics: (topic_names: string[]) => string[],): TopicListInfo {const narrowed_topic = narrow_state.topic();const topic_choice_state: TopicChoiceState = {@@ -203,7 +203,7 @@ export function get_list_info(}if (zoomed) {- topic_names = filter_by_search_term(topic_names, search_term);+ topic_names = filter_topics(topic_names);}if (stream_muted && !zoomed) {diff --git a/web/tests/topic_list_data.test.cjs b/web/tests/topic_list_data.test.cjsindex 4d61ad996a1..0069df62168 100644--- a/web/tests/topic_list_data.test.cjs+++ b/web/tests/topic_list_data.test.cjs@@ -52,7 +52,9 @@ function get_list_info(zoom, search) {const stream_id = general.stream_id;const zoomed = zoom === undefined ? false : zoom;const search_term = search === undefined ? "" : search;- return topic_list_data.get_list_info(stream_id, zoomed, search_term);+ return topic_list_data.get_list_info(stream_id, zoomed, (topics) =>+ topic_list_data.filter_topics_by_search_term(topics, search_term),+ );}function test(label, f) {