mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
drafts: Separate get_formatted_drafts_data
from launch
.
This commit is prep work for implementing drafts undo functionality.
This commit is contained in:
committed by
Tim Abbott
parent
51e367a1cd
commit
1ad95ea000
@@ -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();
|
||||
|
Reference in New Issue
Block a user