topic_list: Clean up component API.

The theory here is that we should prefer to give component callbacks a
simple interface relative to what happened in the component, rather
than a simple implementation relative to what the parent context will
do with that information.  Components should be designed to support
being embedded in many possible contexts, including unit tests and
Storybook pages.  We’re nowhere near that future but we might as well
take steps in that direction.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-06-02 22:51:02 -07:00 committed by Tim Abbott
parent 7ad3225ecc
commit 9d8c6f9186
2 changed files with 15 additions and 15 deletions

View File

@ -10,7 +10,6 @@ import * as popover_menus from "./popover_menus";
import * as scroll_util from "./scroll_util";
import * as stream_topic_history from "./stream_topic_history";
import * as stream_topic_history_util from "./stream_topic_history_util";
import * as sub_store from "./sub_store";
import * as topic_list_data from "./topic_list_data";
import * as vdom from "./vdom";
@ -305,7 +304,7 @@ export function get_topic_search_term() {
return $filter.val().trim();
}
export function initialize({narrow_on_topic_click}) {
export function initialize({on_topic_click}) {
$("#stream_filters").on("click", ".topic-box", (e) => {
if (e.metaKey || e.ctrlKey) {
return;
@ -314,21 +313,10 @@ export function initialize({narrow_on_topic_click}) {
return;
}
// In a more componentized world, we would delegate some
// of this stuff back up to our parents.
const $stream_row = $(e.target).parents(".narrow-filter");
const stream_id = Number.parseInt($stream_row.attr("data-stream-id"), 10);
const sub = sub_store.get(stream_id);
const topic = $(e.target).parents("li").attr("data-topic-name");
narrow_on_topic_click(
[
{operator: "stream", operand: sub.name},
{operator: "topic", operand: topic},
],
{trigger: "sidebar"},
);
on_topic_click(stream_id, topic);
e.preventDefault();
});

View File

@ -99,6 +99,7 @@ import * as stream_edit_subscribers from "./stream_edit_subscribers";
import * as stream_list from "./stream_list";
import * as stream_list_sort from "./stream_list_sort";
import * as stream_settings_ui from "./stream_settings_ui";
import * as sub_store from "./sub_store";
import * as timerender from "./timerender";
import * as tippyjs from "./tippyjs";
import * as top_left_corner from "./top_left_corner";
@ -705,7 +706,18 @@ export function initialize_everything() {
activity.initialize();
emoji_picker.initialize();
pm_list.initialize();
topic_list.initialize({narrow_on_topic_click: narrow.activate});
topic_list.initialize({
on_topic_click(stream_id, topic) {
const sub = sub_store.get(stream_id);
narrow.activate(
[
{operator: "stream", operand: sub.name},
{operator: "topic", operand: topic},
],
{trigger: "sidebar"},
);
},
});
topic_zoom.initialize();
drafts.initialize();
sent_messages.initialize();