Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
list_widget: Allow instance to change load_count as per state.
Aman Agrawald2e3dbeb501a
diff --git a/frontend_tests/node_tests/list_widget.js b/frontend_tests/node_tests/list_widget.jsindex fd5e3cd2be9..56ea518db8d 100644--- a/frontend_tests/node_tests/list_widget.js+++ b/frontend_tests/node_tests/list_widget.js@@ -199,6 +199,12 @@ run_test("not_scrolling", () => {post_scroll__pre_render_callback_called = true;};+ let get_min_load_count_called = false;+ const get_min_load_count = (offset, load_count) => {+ get_min_load_count_called = true;+ return load_count;+ };+for (let i = 0; i < 200; i += 1) {items.push("item " + i);}@@ -208,6 +214,7 @@ run_test("not_scrolling", () => {simplebar_container: scroll_container,is_scroll_position_for_render: () => false,post_scroll__pre_render_callback,+ get_min_load_count,};container.html = (html) => {@@ -229,6 +236,7 @@ run_test("not_scrolling", () => {// appended_data remains the same.assert.deepEqual(container.appended_data.html(), items.slice(0, 80).join(""));assert.equal(post_scroll__pre_render_callback_called, true);+ assert.equal(get_min_load_count_called, true);});run_test("filtering", () => {diff --git a/static/js/list_widget.js b/static/js/list_widget.jsindex 4d63bc91110..e8895a506a3 100644--- a/static/js/list_widget.js+++ b/static/js/list_widget.js@@ -194,7 +194,10 @@ export function create($container, list, opts) {// and renders the next block of messages automatically// into the specified container.widget.render = function (how_many) {- const load_count = how_many || DEFAULTS.LOAD_COUNT;+ let load_count = how_many || DEFAULTS.LOAD_COUNT;+ if (opts.get_min_load_count) {+ load_count = opts.get_min_load_count(meta.offset, load_count);+ }// Stop once the offset reaches the length of the original list.if (meta.offset >= meta.filtered_list.length) {