Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

scroll_to_bottom_button: Use the end of the view as the bottom.

Aman Agrawal857ac9dec4b5
diff --git a/web/src/scroll_to_bottom_button.ts b/web/src/scroll_to_bottom_button.ts
index ee65c777b29..3b898b0b474 100644
--- a/web/src/scroll_to_bottom_button.ts
+++ b/web/src/scroll_to_bottom_button.ts
@@ -7,6 +7,19 @@ import * as message_viewport from "./message_viewport.ts";
import {the} from "./util.ts";
let hide_scroll_to_bottom_timer: ReturnType<typeof setInterval> | undefined;
+
+function above_bottom_of_view(): boolean {
+ assert(message_lists.current !== undefined);
+ return (
+ !message_lists.current.visibly_empty() &&
+ (!message_viewport.bottom_rendered_message_visible() ||
+ !message_lists.current.view.is_fetched_end_rendered() ||
+ // False while newer messages are being fetched, when
+ // there may turn out to be none.
+ message_lists.current.data.fetch_status.can_load_newer_messages())
+ );
+}
+
export function hide_scroll_to_bottom(): void {
const $show_scroll_to_bottom_button = $("#scroll-to-bottom-button-container");
if (message_lists.current === undefined) {
@@ -15,12 +28,7 @@ export function hide_scroll_to_bottom(): void {
return;
}
- if (
- message_viewport.bottom_rendered_message_visible() ||
- message_lists.current.visibly_empty()
- ) {
- // If last message is visible, just hide the
- // scroll to bottom button.
+ if (!above_bottom_of_view()) {
$show_scroll_to_bottom_button.removeClass("show");
return;
}
@@ -40,10 +48,7 @@ export function hide_scroll_to_bottom(): void {
}
export function show_scroll_to_bottom_button(): void {
- if (message_viewport.bottom_rendered_message_visible()) {
- // Only show scroll to bottom button when
- // last message is not visible in the
- // current scroll position.
+ if (!above_bottom_of_view()) {
return;
}
diff --git a/web/tests/scroll_to_bottom_button.test.cjs b/web/tests/scroll_to_bottom_button.test.cjs
index 6aedfc15264..1769d14352f 100644
--- a/web/tests/scroll_to_bottom_button.test.cjs
+++ b/web/tests/scroll_to_bottom_button.test.cjs
@@ -22,11 +22,20 @@ const scroll_to_bottom_button = zrequire("scroll_to_bottom_button");
const $container = () => $("#scroll-to-bottom-button-container");
const $clickable_area = () => $("#scroll-to-bottom-button-clickable-area");
-function set_feed(override, {bottom_visible = true, empty = false} = {}) {
+function set_feed(
+ override,
+ {bottom_visible = true, fetched_end_rendered = true, newest = "found", empty = false} = {},
+) {
override(message_viewport, "bottom_rendered_message_visible", () => bottom_visible, {
unused: false,
});
- override(message_lists, "current", {visibly_empty: () => empty});
+ override(message_lists, "current", {
+ visibly_empty: () => empty,
+ view: {is_fetched_end_rendered: () => fetched_end_rendered},
+ data: {
+ fetch_status: {can_load_newer_messages: () => newest === "not_fetched"},
+ },
+ });
}
function is_shown() {
@@ -77,12 +86,36 @@ test("hidden at the bottom of the feed", ({override}) => {
test("hidden in an empty feed", ({override}) => {
set_feed(override, {bottom_visible: false, empty: true});
- $container().addClass("show");
+ scroll_to_bottom_button.show_scroll_to_bottom_button();
+ assert.ok(!is_shown());
+
+ $container().addClass("show");
scroll_to_bottom_button.hide_scroll_to_bottom();
assert.ok(!is_shown());
});
+test("shown when newer messages are fetched but not rendered", ({override}) => {
+ set_feed(override, {fetched_end_rendered: false});
+
+ mouse_scroll();
+ assert.ok(is_shown());
+});
+
+test("shown when newer messages are yet to be fetched", ({override}) => {
+ set_feed(override, {newest: "not_fetched"});
+
+ mouse_scroll();
+ assert.ok(is_shown());
+});
+
+test("not shown while the newest messages are being fetched", ({override}) => {
+ set_feed(override, {newest: "loading"});
+
+ mouse_scroll();
+ assert.ok(!is_shown());
+});
+
test("shown by a mouse scroll above the bottom", ({override}) => {
set_feed(override, {bottom_visible: false});