mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 00:46:03 +00:00
dropdown_widget: Pass current value to get_options to avoid hacky this.
This commit is contained in:
@@ -73,7 +73,7 @@ export class DropdownWidget {
|
||||
widget_selector: string;
|
||||
widget_wrapper_id: string;
|
||||
widget_value_selector: string;
|
||||
get_options: () => Option[];
|
||||
get_options: (current_value: string | number | undefined) => Option[];
|
||||
item_click_callback: (
|
||||
event: JQuery.ClickEvent,
|
||||
instance: tippy.Instance,
|
||||
@@ -200,7 +200,10 @@ export class DropdownWidget {
|
||||
"input.dropdown-list-search-input",
|
||||
);
|
||||
|
||||
this.list_widget = ListWidget.create($dropdown_list_body, this.get_options(), {
|
||||
this.list_widget = ListWidget.create(
|
||||
$dropdown_list_body,
|
||||
this.get_options(this.current_value),
|
||||
{
|
||||
name: `${CSS.escape(this.widget_name)}-list-widget`,
|
||||
get_item: ListWidget.default_get_item,
|
||||
modifier_html(item) {
|
||||
@@ -213,7 +216,8 @@ export class DropdownWidget {
|
||||
},
|
||||
},
|
||||
$simplebar_container: $popper.find(".dropdown-list-wrapper"),
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
$search_input.on("input.list_widget_filter", () => {
|
||||
this.show_empty_if_no_items($popper);
|
||||
@@ -371,7 +375,7 @@ export class DropdownWidget {
|
||||
this.current_value = value;
|
||||
}
|
||||
|
||||
const all_options = this.get_options();
|
||||
const all_options = this.get_options(this.current_value);
|
||||
const option = all_options.find((option) => option.unique_id === this.current_value);
|
||||
|
||||
// If provided, show custom text if cannot find current option.
|
||||
|
||||
@@ -33,19 +33,19 @@ export const COMMON_DROPDOWN_WIDGET_PARAMS = {
|
||||
disable_for_spectators: true,
|
||||
};
|
||||
|
||||
export function filters_dropdown_options() {
|
||||
export function filters_dropdown_options(current_value) {
|
||||
return [
|
||||
{
|
||||
unique_id: FILTERS.FOLLOWED_TOPICS,
|
||||
name: $t({defaultMessage: "Followed topics"}),
|
||||
description: $t({defaultMessage: "Only topics you follow"}),
|
||||
bold_current_selection: this.current_value === FILTERS.FOLLOWED_TOPICS,
|
||||
bold_current_selection: current_value === FILTERS.FOLLOWED_TOPICS,
|
||||
},
|
||||
{
|
||||
unique_id: FILTERS.UNMUTED_TOPICS,
|
||||
name: $t({defaultMessage: "Standard view"}),
|
||||
description: $t({defaultMessage: "All unmuted topics"}),
|
||||
bold_current_selection: this.current_value === FILTERS.UNMUTED_TOPICS,
|
||||
bold_current_selection: current_value === FILTERS.UNMUTED_TOPICS,
|
||||
},
|
||||
{
|
||||
unique_id: FILTERS.ALL_TOPICS,
|
||||
@@ -53,7 +53,7 @@ export function filters_dropdown_options() {
|
||||
description: $t({
|
||||
defaultMessage: "Includes muted streams and topics",
|
||||
}),
|
||||
bold_current_selection: this.current_value === FILTERS.ALL_TOPICS,
|
||||
bold_current_selection: current_value === FILTERS.ALL_TOPICS,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user