Skip to content

Commit

Permalink
compose: Deduplicate code for fetching recipient switcher options.
Browse files Browse the repository at this point in the history
  • Loading branch information
evykassirer authored and timabbott committed Apr 28, 2023
1 parent 6c79790 commit 0634457
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions web/src/compose_recipient.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,7 @@ export function on_compose_select_recipient_update(new_value) {
}

export function update_stream_dropdown_options() {
const streams_list = stream_data
.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);
compose_recipient_widget.replace_data(get_options_for_recipient_widget());
}

export function possibly_update_dropdown_selection(old_stream_name, new_stream_name) {
Expand All @@ -159,8 +143,8 @@ export function possibly_update_dropdown_selection(old_stream_name, new_stream_n
}
}

export function initialize() {
const streams_list = stream_data
function get_options_for_recipient_widget() {
return stream_data
.subscribed_subs()
.map((stream) => ({
name: stream.name,
Expand All @@ -176,9 +160,12 @@ export function initialize() {
}
return 0;
});
}

export function initialize() {
const opts = {
widget_name: "compose_select_recipient",
data: streams_list,
data: get_options_for_recipient_widget(),
default_text: $t({defaultMessage: "Select a stream"}),
value: null,
on_update: on_compose_select_recipient_update,
Expand Down

0 comments on commit 0634457

Please sign in to comment.