Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
drafts: Separate `get_formatted_drafts_data` from `launch`.
Aditya Kumar Kasaudhan1ad95ea00047
diff --git a/web/src/drafts_overlay_ui.ts b/web/src/drafts_overlay_ui.tsindex 6bbb25baf3c..adf1159665f 100644--- a/web/src/drafts_overlay_ui.ts+++ b/web/src/drafts_overlay_ui.ts@@ -168,10 +168,29 @@ function get_header_for_narrow_drafts(): string {return $t({defaultMessage: "Drafts from {recipient}"}, {recipient});}-function render_widgets(narrow_drafts: FormattedDraft[], other_drafts: FormattedDraft[]): void {- $("#drafts_table").empty();-+function get_formatted_drafts_data(): {+ narrow_drafts: FormattedDraft[];+ other_drafts: FormattedDraft[];+ narrow_drafts_header: string;+} {+ const all_drafts = drafts.draft_model.get();+ const narrow_drafts_raw = drafts.filter_drafts_by_compose_box_and_recipient(all_drafts);+ const other_drafts_raw = _.pick(+ all_drafts,+ _.difference(Object.keys(all_drafts), Object.keys(narrow_drafts_raw)),+ );+ const narrow_drafts = format_drafts(narrow_drafts_raw);+ const other_drafts = format_drafts(other_drafts_raw);const narrow_drafts_header = get_header_for_narrow_drafts();+ return {narrow_drafts, other_drafts, narrow_drafts_header};+}++function render_widgets(+ narrow_drafts: FormattedDraft[],+ other_drafts: FormattedDraft[],+ narrow_drafts_header: string,+): void {+ $("#drafts_table").empty();const rendered = render_draft_table_body({narrow_drafts_header,@@ -276,23 +295,16 @@ function setup_bulk_actions_handlers(): void {}export function launch(): void {- const all_drafts = drafts.draft_model.get();- const narrow_drafts = drafts.filter_drafts_by_compose_box_and_recipient(all_drafts);- const other_drafts = _.pick(- all_drafts,- _.difference(Object.keys(all_drafts), Object.keys(narrow_drafts)),- );- const formatted_narrow_drafts = format_drafts(narrow_drafts);- const formatted_other_drafts = format_drafts(other_drafts);+ const {narrow_drafts, other_drafts, narrow_drafts_header} = get_formatted_drafts_data();- render_widgets(formatted_narrow_drafts, formatted_other_drafts);+ render_widgets(narrow_drafts, other_drafts, narrow_drafts_header);// We need to force a style calculation on the newly created// element in order for the CSS transition to take effect.$("#draft_overlay").css("opacity");open_overlay();- const first_element_id = [...formatted_narrow_drafts, ...formatted_other_drafts][0]?.draft_id;+ const first_element_id = [...narrow_drafts, ...other_drafts][0]?.draft_id;messages_overlay_ui.set_initial_element(first_element_id, keyboard_handling_context);setup_event_handlers();setup_bulk_actions_handlers();