mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 12:33:40 +00:00
message view: Refactor top loading indicators.
This commit makes the `loading_older_messages_indicator` similar to the `loading_newer_messages_indicator`. Now all the decisions about whether to show a loading indicator will be made from the `fetch_status` API. We still hide the indicators everytime the view is changed, as explained in the previous commit.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
const FetchStatus = zrequire('fetch_status');
|
||||
set_global('message_scroll', {
|
||||
hide_loading_older: () => {},
|
||||
show_loading_older: () => {},
|
||||
hide_loading_newer: () => {},
|
||||
show_loading_newer: () => {},
|
||||
});
|
||||
@@ -54,7 +56,7 @@ run_test('basics', () => {
|
||||
reset();
|
||||
|
||||
fetch_status.start_newer_batch({ update_loading_indicator: false });
|
||||
fetch_status.start_older_batch();
|
||||
fetch_status.start_older_batch({ update_loading_indicator: false });
|
||||
|
||||
blocked_newer();
|
||||
blocked_older();
|
||||
@@ -80,7 +82,7 @@ run_test('basics', () => {
|
||||
reset();
|
||||
|
||||
fetch_status.start_newer_batch({ update_loading_indicator: true });
|
||||
fetch_status.start_older_batch();
|
||||
fetch_status.start_older_batch({ update_loading_indicator: true });
|
||||
|
||||
blocked_newer();
|
||||
blocked_older();
|
||||
@@ -103,13 +105,14 @@ run_test('basics', () => {
|
||||
|
||||
can_load_older();
|
||||
|
||||
fetch_status.start_older_batch();
|
||||
fetch_status.start_older_batch({ update_loading_indicator: false });
|
||||
|
||||
blocked_older();
|
||||
can_load_newer();
|
||||
can_load_history();
|
||||
|
||||
fetch_status.finish_older_batch({
|
||||
update_loading_indicator: true,
|
||||
found_oldest: false,
|
||||
history_limited: false,
|
||||
});
|
||||
@@ -118,13 +121,14 @@ run_test('basics', () => {
|
||||
can_load_newer();
|
||||
can_load_history();
|
||||
|
||||
fetch_status.start_older_batch();
|
||||
fetch_status.start_older_batch({ update_loading_indicator: true });
|
||||
|
||||
blocked_older();
|
||||
can_load_newer();
|
||||
can_load_history();
|
||||
|
||||
fetch_status.finish_older_batch({
|
||||
update_loading_indicator: true,
|
||||
found_oldest: true,
|
||||
history_limited: true,
|
||||
});
|
||||
|
||||
@@ -26,6 +26,8 @@ set_global('ui_report', {
|
||||
set_global('channel', {});
|
||||
set_global('document', 'document-stub');
|
||||
set_global('message_scroll', {
|
||||
show_loading_older: noop,
|
||||
hide_loading_older: noop,
|
||||
show_loading_newer: noop,
|
||||
hide_loading_newer: noop,
|
||||
});
|
||||
|
||||
@@ -8,14 +8,20 @@ const FetchStatus = function () {
|
||||
let found_newest = false;
|
||||
let history_limited = false;
|
||||
|
||||
self.start_older_batch = function () {
|
||||
self.start_older_batch = function (opts) {
|
||||
loading_older = true;
|
||||
if (opts.update_loading_indicator) {
|
||||
message_scroll.show_loading_older();
|
||||
}
|
||||
};
|
||||
|
||||
self.finish_older_batch = function (opts) {
|
||||
loading_older = false;
|
||||
found_oldest = opts.found_oldest;
|
||||
history_limited = opts.history_limited;
|
||||
if (opts.update_loading_indicator) {
|
||||
message_scroll.hide_loading_older();
|
||||
}
|
||||
};
|
||||
|
||||
self.can_load_older_messages = function () {
|
||||
|
||||
@@ -64,6 +64,7 @@ function get_messages_success(data, opts) {
|
||||
const update_loading_indicator = opts.msg_list === current_msg_list;
|
||||
if (opts.num_before > 0) {
|
||||
opts.msg_list.data.fetch_status.finish_older_batch({
|
||||
update_loading_indicator: update_loading_indicator,
|
||||
found_oldest: data.found_oldest,
|
||||
history_limited: data.history_limited,
|
||||
});
|
||||
@@ -73,6 +74,7 @@ function get_messages_success(data, opts) {
|
||||
// which is never rendered (and just used for
|
||||
// prepopulating narrowed views).
|
||||
message_list.all.data.fetch_status.finish_older_batch({
|
||||
update_loading_indicator: false,
|
||||
found_oldest: data.found_oldest,
|
||||
history_limited: data.history_limited,
|
||||
});
|
||||
@@ -174,9 +176,13 @@ exports.load_messages = function (opts) {
|
||||
|
||||
const update_loading_indicator = opts.msg_list === current_msg_list;
|
||||
if (opts.num_before > 0) {
|
||||
opts.msg_list.data.fetch_status.start_older_batch();
|
||||
opts.msg_list.data.fetch_status.start_older_batch({
|
||||
update_loading_indicator: update_loading_indicator,
|
||||
});
|
||||
if (opts.msg_list === home_msg_list) {
|
||||
message_list.all.data.fetch_status.start_older_batch();
|
||||
message_list.all.data.fetch_status.start_older_batch({
|
||||
update_loading_indicator: update_loading_indicator,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,13 +290,9 @@ exports.maybe_load_older_messages = function (opts) {
|
||||
return;
|
||||
}
|
||||
|
||||
opts.show_loading();
|
||||
exports.do_backfill({
|
||||
msg_list: msg_list,
|
||||
num_before: consts.backward_batch_size,
|
||||
cont: function () {
|
||||
opts.hide_loading();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -63,8 +63,6 @@ exports.scroll_finished = function () {
|
||||
if (message_viewport.at_top()) {
|
||||
message_fetch.maybe_load_older_messages({
|
||||
msg_list: current_msg_list,
|
||||
show_loading: exports.show_loading_older,
|
||||
hide_loading: exports.hide_loading_older,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -299,8 +299,6 @@ exports.activate = function (raw_operators, opts) {
|
||||
id_info: id_info,
|
||||
select_offset: then_select_offset,
|
||||
});
|
||||
} else {
|
||||
message_scroll.show_loading_older();
|
||||
}
|
||||
|
||||
// Put the narrow operators in the URL fragment.
|
||||
|
||||
Reference in New Issue
Block a user