compose: Deduplicate code for fetching recipient switcher options.

This commit is contained in:
evykassirer
2023-04-22 14:40:14 -07:00
committed by Tim Abbott
parent 6c797904f2
commit 0634457731

View File

@@ -133,23 +133,7 @@ export function on_compose_select_recipient_update(new_value) {
} }
export function update_stream_dropdown_options() { export function update_stream_dropdown_options() {
const streams_list = stream_data compose_recipient_widget.replace_data(get_options_for_recipient_widget());
.subscribed_subs()
.map((stream) => ({
name: stream.name,
value: stream.name,
stream,
}))
.sort((a, b) => {
if (a.name.toLowerCase() < b.name.toLowerCase()) {
return -1;
}
if (a.name.toLowerCase() > b.name.toLowerCase()) {
return 1;
}
return 0;
});
compose_recipient_widget.replace_data(streams_list);
} }
export function possibly_update_dropdown_selection(old_stream_name, new_stream_name) { export function possibly_update_dropdown_selection(old_stream_name, new_stream_name) {
@@ -159,8 +143,8 @@ export function possibly_update_dropdown_selection(old_stream_name, new_stream_n
} }
} }
export function initialize() { function get_options_for_recipient_widget() {
const streams_list = stream_data return stream_data
.subscribed_subs() .subscribed_subs()
.map((stream) => ({ .map((stream) => ({
name: stream.name, name: stream.name,
@@ -176,9 +160,12 @@ export function initialize() {
} }
return 0; return 0;
}); });
}
export function initialize() {
const opts = { const opts = {
widget_name: "compose_select_recipient", widget_name: "compose_select_recipient",
data: streams_list, data: get_options_for_recipient_widget(),
default_text: $t({defaultMessage: "Select a stream"}), default_text: $t({defaultMessage: "Select a stream"}),
value: null, value: null,
on_update: on_compose_select_recipient_update, on_update: on_compose_select_recipient_update,