Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_feed: Pin the top-of-feed gutter below the navbar.
Shubham Padia38f7e6c34ddb
diff --git a/templates/zerver/app/index.html b/templates/zerver/app/index.htmlindex b1b96ceeae8..87ad752e2ed 100644--- a/templates/zerver/app/index.html+++ b/templates/zerver/app/index.html@@ -253,6 +253,7 @@ Accessing messages requires an account and Zulip API key.</div><div id="message_feed_container"><div class="message-feed" id="main_div">+ <div id="top-of-feed-gutter" aria-hidden="true"></div><div id="top-of-feed-loading-indicator" aria-hidden="true"></div><div id="message_feed_errors_container"></div><div id="message-lists-container"></div>diff --git a/web/src/message_feed_loading.ts b/web/src/message_feed_loading.tsindex 31194d95fa5..b9251a948d3 100644--- a/web/src/message_feed_loading.ts+++ b/web/src/message_feed_loading.ts@@ -11,8 +11,17 @@ let loading_newer_messages_indicator_showing = false;let initial_page_load_pending = false;let fetching_older_messages = false;+function top_of_feed_in_view(): boolean {+ // Same check as message_viewport.at_rendered_top, duplicated here+ // to avoid an import cycle.+ return window.scrollY <= 0;+}+function update_top_of_feed_indicator(): void {- const should_show_indicator = initial_page_load_pending || fetching_older_messages;+ // The initial page load always shows the indicator. Loading older+ // messages only shows it when the user is at the top of the feed.+ const should_show_indicator =+ initial_page_load_pending || (fetching_older_messages && top_of_feed_in_view());if (should_show_indicator === top_of_feed_indicator_showing) {return;}@@ -25,6 +34,14 @@ function update_top_of_feed_indicator(): void {}}+export function update_for_scroll_position(): void {+ // Scrolling can bring the top of the feed into or out of view while+ // older messages are being fetched.+ if (fetching_older_messages) {+ update_top_of_feed_indicator();+ }+}+export function show_loading_initial_page(): void {initial_page_load_pending = true;update_top_of_feed_indicator();diff --git a/web/src/message_scroll.ts b/web/src/message_scroll.tsindex 9291d82145d..9e64955051b 100644--- a/web/src/message_scroll.ts+++ b/web/src/message_scroll.ts@@ -2,6 +2,7 @@ import {$} from "jquery";import _ from "lodash";import * as compose_banner from "./compose_banner.ts";+import * as message_feed_loading from "./message_feed_loading.ts";import * as message_fetch from "./message_fetch.ts";import * as message_lists from "./message_lists.ts";import * as message_scroll_state from "./message_scroll_state.ts";@@ -98,6 +99,7 @@ export function initialize(): void {}message_lists.current.view.update_sticky_recipient_headers();+ message_feed_loading.update_for_scroll_position();scroll_finish();}, 50),);diff --git a/web/src/message_view.ts b/web/src/message_view.tsindex 3145f058b25..599ac4bfa6c 100644--- a/web/src/message_view.ts+++ b/web/src/message_view.ts@@ -354,7 +354,7 @@ function get_selected_message_top_offset(is_first_message_in_narrow = false): nu// the top of the message and the sticky header.if (is_first_message_in_narrow) {final_offset +=- ($("#top-of-feed-loading-indicator").outerHeight(true) ?? 0) ++ ($("#top-of-feed-gutter").outerHeight(true) ?? 0) +($("#message_feed_errors_container").outerHeight(true) ?? 0);}return final_offset;diff --git a/web/styles/print.css b/web/styles/print.cssindex 85a7d394142..1c3c748feec 100644--- a/web/styles/print.css+++ b/web/styles/print.css@@ -15,6 +15,7 @@.column-left,#userlist-toggle,.message_length_controller,+ #top-of-feed-gutter,#top-of-feed-loading-indicator,#message_feed_errors_container,#bottom_whitespace,diff --git a/web/styles/zulip.css b/web/styles/zulip.cssindex 4b8b87413f5..05b72475f29 100644--- a/web/styles/zulip.css+++ b/web/styles/zulip.css@@ -581,8 +581,7 @@ body.has-overlay-scrollbar {}#message_feed_container {- /* The gutter below the navbar is the top-of-feed loading box; see- #top-of-feed-loading-indicator. */+ /* The gutter below the navbar is #top-of-feed-gutter. */padding-top: var(--navbar-fixed-height);}@@ -1230,31 +1229,52 @@ nav {font-family: "Source Code Pro", monospace;}+#top-of-feed-gutter {+ position: sticky;+ top: var(--navbar-fixed-height);+ height: var(--header-padding-bottom);+ /* Below sticky recipient bars (z-index: 4), so that a bar pushed+ out by the next one slides up under the navbar. */+ z-index: 3;+ background-color: var(--color-background);++ /* While the loading line shows, the gutter covers recipient bars+ instead, so that a bar pushed out by the next one never slides+ through the line. */+ #main_div:has(> #top-of-feed-loading-indicator:is(.loading, .fade-out))+ > & {+ z-index: 5;+ }+}++/* The loading line is centered in the space between the navbar and+ the recipient bar's contents. At the top of the feed, that space is+ the gutter plus the first bar's top margin, so the line is centered+ on the gutter's bottom edge. Once a recipient bar is stuck, the+ gutter covers the bar's top margin, so the line sticks at the middle+ of the gutter. This element takes no space in the layout. */#top-of-feed-loading-indicator {/* How much of the line the pulse covers; the sweep keyframesuse this to travel the full width of the line. */--loading-pulse-fraction: 0.3;- position: relative;- height: var(--header-padding-bottom);- /* Above the first recipient bar (see .message-feed .message_header- in message_header.css), whose empty top margin the line hangs- into. */+ position: sticky;+ top: calc(var(--navbar-fixed-height) + var(--header-padding-bottom) / 2);+ height: 0;+ /* Same as #top-of-feed-gutter, so that this is drawn above sticky+ recipient bars (z-index: 4) and, coming later, above+ #top-of-feed-gutter. */z-index: 5;- /* Clip the pulse as it sweeps past the sides, but let the line- hang out below, over the recipient bar's empty top margin. */+ /* Clip the pulse as it sweeps past the sides. */overflow: clip visible;&::before,&::after {content: "";position: absolute;- /* Centered in the space between the navbar and the recipient- bar's contents, which is the gutter plus the bar's equal top- margin: that is, centered on the gutter's bottom edge. */- bottom: -1.5px;+ top: -1px;left: 0;- height: 3px;+ height: 2px;/* Fade in and out rather than popping. */opacity: 0;transition: opacity 200ms ease-in-out;diff --git a/web/tests/message_feed_loading.test.cjs b/web/tests/message_feed_loading.test.cjsindex b17cfb969e5..2b624ce9f39 100644--- a/web/tests/message_feed_loading.test.cjs+++ b/web/tests/message_feed_loading.test.cjs@@ -12,7 +12,18 @@ function is_loading() {return $("#top-of-feed-loading-indicator").hasClass("loading");}-run_test("initial page load and older fetches share the indicator", () => {+function set_top_of_feed_in_view(in_view) {+ window.scrollY = in_view ? 0 : 400;+}++function test(label, f) {+ run_test(label, (helpers) => {+ set_top_of_feed_in_view(true);+ f(helpers);+ });+}++test("initial page load and older fetches share the indicator", () => {message_feed_loading.show_loading_initial_page();assert.ok(is_loading());@@ -36,7 +47,7 @@ run_test("initial page load and older fetches share the indicator", () => {assert.ok(!is_loading());});-run_test("page load finishing during a fetch keeps the indicator", () => {+test("page load finishing during a fetch keeps the indicator", () => {message_feed_loading.show_loading_initial_page();message_feed_loading.show_loading_older();message_feed_loading.hide_loading_initial_page();@@ -44,3 +55,37 @@ run_test("page load finishing during a fetch keeps the indicator", () => {message_feed_loading.hide_loading_older();assert.ok(!is_loading());});++test("older fetches are only shown while the top of the feed is in view", () => {+ set_top_of_feed_in_view(false);+ message_feed_loading.show_loading_older();+ assert.ok(!is_loading());++ // Scrolling the top of the feed into view during the fetch shows+ // the indicator.+ set_top_of_feed_in_view(true);+ message_feed_loading.update_for_scroll_position();+ assert.ok(is_loading());+ message_feed_loading.hide_loading_older();+ assert.ok(!is_loading());++ // Scrolling it out of view during a fetch hides the indicator.+ message_feed_loading.show_loading_older();+ assert.ok(is_loading());+ set_top_of_feed_in_view(false);+ message_feed_loading.update_for_scroll_position();+ assert.ok(!is_loading());+ message_feed_loading.hide_loading_older();++ // Scrolling with no fetch in flight changes nothing.+ set_top_of_feed_in_view(true);+ message_feed_loading.update_for_scroll_position();+ assert.ok(!is_loading());++ // The initial page load is shown wherever the feed is scrolled to.+ set_top_of_feed_in_view(false);+ message_feed_loading.show_loading_initial_page();+ assert.ok(is_loading());+ message_feed_loading.hide_loading_initial_page();+ assert.ok(!is_loading());+});