mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
drafts: Enable dynamic re-rendering of draft list in overlay.
This commit laying the groundwork for dynamic re-rendering of drafts. Previously, the draft list was rendered once with the overlay, and re-rendering wasn't needed. However, to support features like "undo," we now need to re-render the draft list dynamically.
This commit is contained in:
committed by
Tim Abbott
parent
1ad95ea000
commit
9a4de8d9b8
@@ -4,6 +4,7 @@ import _ from "lodash";
|
|||||||
import assert from "minimalistic-assert";
|
import assert from "minimalistic-assert";
|
||||||
|
|
||||||
import render_draft_table_body from "../templates/draft_table_body.hbs";
|
import render_draft_table_body from "../templates/draft_table_body.hbs";
|
||||||
|
import render_drafts_list from "../templates/drafts_list.hbs";
|
||||||
|
|
||||||
import * as browser_history from "./browser_history.ts";
|
import * as browser_history from "./browser_history.ts";
|
||||||
import * as compose_actions from "./compose_actions.ts";
|
import * as compose_actions from "./compose_actions.ts";
|
||||||
@@ -190,15 +191,24 @@ function render_widgets(
|
|||||||
other_drafts: FormattedDraft[],
|
other_drafts: FormattedDraft[],
|
||||||
narrow_drafts_header: string,
|
narrow_drafts_header: string,
|
||||||
): void {
|
): void {
|
||||||
$("#drafts_table").empty();
|
|
||||||
|
|
||||||
const rendered = render_draft_table_body({
|
|
||||||
narrow_drafts_header,
|
|
||||||
narrow_drafts,
|
|
||||||
other_drafts,
|
|
||||||
});
|
|
||||||
const $drafts_table = $("#drafts_table");
|
const $drafts_table = $("#drafts_table");
|
||||||
$drafts_table.append($(rendered));
|
if ($(".drafts-list").length === 0) {
|
||||||
|
const rendered = render_draft_table_body({
|
||||||
|
context: {
|
||||||
|
narrow_drafts_header,
|
||||||
|
narrow_drafts,
|
||||||
|
other_drafts,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
$drafts_table.append($(rendered));
|
||||||
|
} else {
|
||||||
|
const rendered = render_drafts_list({
|
||||||
|
narrow_drafts_header,
|
||||||
|
narrow_drafts,
|
||||||
|
other_drafts,
|
||||||
|
});
|
||||||
|
$(".drafts-list").replaceWith($(rendered));
|
||||||
|
}
|
||||||
if ($("#drafts_table .overlay-message-row").length > 0) {
|
if ($("#drafts_table .overlay-message-row").length > 0) {
|
||||||
$("#drafts_table .no-drafts").hide();
|
$("#drafts_table .no-drafts").hide();
|
||||||
// Update possible dynamic elements.
|
// Update possible dynamic elements.
|
||||||
@@ -297,6 +307,7 @@ function setup_bulk_actions_handlers(): void {
|
|||||||
export function launch(): void {
|
export function launch(): void {
|
||||||
const {narrow_drafts, other_drafts, narrow_drafts_header} = get_formatted_drafts_data();
|
const {narrow_drafts, other_drafts, narrow_drafts_header} = get_formatted_drafts_data();
|
||||||
|
|
||||||
|
$("#drafts_table").empty();
|
||||||
render_widgets(narrow_drafts, other_drafts, narrow_drafts_header);
|
render_widgets(narrow_drafts, other_drafts, narrow_drafts_header);
|
||||||
|
|
||||||
// We need to force a style calculation on the newly created
|
// We need to force a style calculation on the newly created
|
||||||
|
@@ -23,24 +23,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="drafts-list overlay-messages-list">
|
{{> drafts_list context }}
|
||||||
<div class="no-drafts no-overlay-messages">
|
|
||||||
{{t 'No drafts.'}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="drafts-from-conversation">
|
|
||||||
<h2>{{narrow_drafts_header}}</h2>
|
|
||||||
{{#each narrow_drafts}}
|
|
||||||
{{> draft .}}
|
|
||||||
{{/each}}
|
|
||||||
</div>
|
|
||||||
<div id="other-drafts">
|
|
||||||
<h2 id="other-drafts-header">{{t "Other drafts" }}</h2>
|
|
||||||
{{#each other_drafts}}
|
|
||||||
{{> draft .}}
|
|
||||||
{{/each}}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
18
web/templates/drafts_list.hbs
Normal file
18
web/templates/drafts_list.hbs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<div class="drafts-list overlay-messages-list">
|
||||||
|
<div class="no-drafts no-overlay-messages">
|
||||||
|
{{t 'No drafts.'}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="drafts-from-conversation">
|
||||||
|
<h2>{{narrow_drafts_header}}</h2>
|
||||||
|
{{#each narrow_drafts}}
|
||||||
|
{{> draft .}}
|
||||||
|
{{/each}}
|
||||||
|
</div>
|
||||||
|
<div id="other-drafts">
|
||||||
|
<h2 id="other-drafts-header">{{t "Other drafts" }}</h2>
|
||||||
|
{{#each other_drafts}}
|
||||||
|
{{> draft .}}
|
||||||
|
{{/each}}
|
||||||
|
</div>
|
||||||
|
</div>
|
@@ -646,8 +646,8 @@ test("format_drafts", ({override, override_rewire, mock_template}) => {
|
|||||||
|
|
||||||
mock_template("draft_table_body.hbs", false, (data) => {
|
mock_template("draft_table_body.hbs", false, (data) => {
|
||||||
// Tests formatting and time-sorting of drafts
|
// Tests formatting and time-sorting of drafts
|
||||||
assert.deepEqual(data.narrow_drafts, []);
|
assert.deepEqual(data.context.narrow_drafts, []);
|
||||||
assert.deepEqual(data.other_drafts, expected);
|
assert.deepEqual(data.context.other_drafts, expected);
|
||||||
assert.ok(data);
|
assert.ok(data);
|
||||||
return "<draft table stub>";
|
return "<draft table stub>";
|
||||||
});
|
});
|
||||||
@@ -657,6 +657,7 @@ test("format_drafts", ({override, override_rewire, mock_template}) => {
|
|||||||
const $unread_count = $("<unread-count-stub>");
|
const $unread_count = $("<unread-count-stub>");
|
||||||
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
||||||
|
|
||||||
|
$.create(".drafts-list", {children: []});
|
||||||
$.create("#drafts_table .overlay-message-row", {children: []});
|
$.create("#drafts_table .overlay-message-row", {children: []});
|
||||||
$(".draft-selection-checkbox").filter = () => [];
|
$(".draft-selection-checkbox").filter = () => [];
|
||||||
drafts_overlay_ui.launch();
|
drafts_overlay_ui.launch();
|
||||||
@@ -800,8 +801,8 @@ test("filter_drafts", ({override, override_rewire, mock_template}) => {
|
|||||||
|
|
||||||
mock_template("draft_table_body.hbs", false, (data) => {
|
mock_template("draft_table_body.hbs", false, (data) => {
|
||||||
// Tests splitting up drafts by current narrow.
|
// Tests splitting up drafts by current narrow.
|
||||||
assert.deepEqual(data.narrow_drafts, expected_pm_drafts);
|
assert.deepEqual(data.context.narrow_drafts, expected_pm_drafts);
|
||||||
assert.deepEqual(data.other_drafts, expected_other_drafts);
|
assert.deepEqual(data.context.other_drafts, expected_other_drafts);
|
||||||
return "<draft table stub>";
|
return "<draft table stub>";
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -813,6 +814,7 @@ test("filter_drafts", ({override, override_rewire, mock_template}) => {
|
|||||||
override(user_pill, "get_user_ids", () => [aaron.user_id]);
|
override(user_pill, "get_user_ids", () => [aaron.user_id]);
|
||||||
compose_state.set_message_type("private");
|
compose_state.set_message_type("private");
|
||||||
|
|
||||||
|
$.create(".drafts-list", {children: []});
|
||||||
$.create("#drafts_table .overlay-message-row", {children: []});
|
$.create("#drafts_table .overlay-message-row", {children: []});
|
||||||
$(".draft-selection-checkbox").filter = () => [];
|
$(".draft-selection-checkbox").filter = () => [];
|
||||||
drafts_overlay_ui.launch();
|
drafts_overlay_ui.launch();
|
||||||
|
Reference in New Issue
Block a user