Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
recent_view: Extract function to check when to render more items.
Aman Agrawalbc55c831ea45
diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.tsindex d073c617629..f91d8f36ce6 100644--- a/web/src/recent_view_ui.ts+++ b/web/src/recent_view_ui.ts@@ -1267,22 +1267,6 @@ function recenter_focus_if_off_screen(): void {}}-function is_scroll_position_for_render(): boolean {- const scroll_position = window.scrollY;- const window_height = window.innerHeight;- // We allocate `--max-unmaximized-compose-height` in empty space- // below the last rendered row in recent view.- //- // We don't want user to see this empty space until there are no- // new rows to render when the user is scrolling to the bottom of- // the view. So, we render new rows when user has scrolled 2 / 3- // of (the total scrollable height - the empty space).- const compose_max_height = $("html").css("--max-unmaximized-compose-height");- assert(typeof compose_max_height === "string");- const scroll_max = document.body.scrollHeight - Number.parseInt(compose_max_height, 10);- return scroll_position + window_height >= (2 / 3) * scroll_max;-}-function callback_after_render(): void {// It is important to restore the scroll position as soon// as the rendering is complete to avoid scroll jumping.@@ -1385,7 +1369,7 @@ export function complete_rerender(): void {html_selector: get_topic_row,$simplebar_container: $("html"),callback_after_render,- is_scroll_position_for_render,+ is_scroll_position_for_render: views_util.is_scroll_position_for_render,post_scroll__pre_render_callback() {// Update the focused element for keyboard navigation if needed.recenter_focus_if_off_screen();diff --git a/web/src/views_util.ts b/web/src/views_util.tsindex b71260bee53..1c0714e7bf3 100644--- a/web/src/views_util.ts+++ b/web/src/views_util.ts@@ -1,4 +1,5 @@import $ from "jquery";+import assert from "minimalistic-assert";import type * as tippy from "tippy.js";import * as activity_ui from "./activity_ui.ts";@@ -151,3 +152,19 @@ export function is_in_focus(): boolean {!$(".navbar-item").is(":focus"));}++export function is_scroll_position_for_render(): boolean {+ const scroll_position = window.scrollY;+ const window_height = window.innerHeight;+ // We allocate `--max-unmaximized-compose-height` in empty space+ // below the last rendered row in recent view.+ //+ // We don't want user to see this empty space until there are no+ // new rows to render when the user is scrolling to the bottom of+ // the view. So, we render new rows when user has scrolled 2 / 3+ // of (the total scrollable height - the empty space).+ const compose_max_height = $("html").css("--max-unmaximized-compose-height");+ assert(typeof compose_max_height === "string");+ const scroll_max = document.body.scrollHeight - Number.parseInt(compose_max_height, 10);+ return scroll_position + window_height >= (2 / 3) * scroll_max;+}