Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(issues): hide Jump to latest once the reader scrolls past the top fifth (MUL-8324) (#9634)
Multica Eve1223524b5e7b
diff --git a/packages/views/issues/hooks/use-jump-to-latest.test.tsx b/packages/views/issues/hooks/use-jump-to-latest.test.tsxindex 0ecd5b8709..c5b4e6acce 100644--- a/packages/views/issues/hooks/use-jump-to-latest.test.tsx+++ b/packages/views/issues/hooks/use-jump-to-latest.test.tsx@@ -77,16 +77,25 @@ describe("useJumpToLatest", () => {expect(screen.queryByRole("button", { name: "latest" })).toBeNull();});- it("hides once the reader is past the middle of a long page", () => {+ it("hides once the reader has scrolled past the top fifth of the page", () => {render(<Harness metrics={{ scrollHeight: 4000, clientHeight: 500 }} />);const scroller = screen.getByTestId("scroller");- scroller.scrollTop = 1400; // 2100px left below: more than half the page+ scroller.scrollTop = 800; // exactly 20% of the pagefireEvent.scroll(scroller);flushFrame();expect(screen.getByRole("button", { name: "latest" })).toBeTruthy();- scroller.scrollTop = 1600; // 1900px left: still several screens, but past the middle+ scroller.scrollTop = 900; // past 20%, though several screens are still below+ fireEvent.scroll(scroller);+ flushFrame();+ expect(screen.queryByRole("button", { name: "latest" })).toBeNull();+ });++ it("stays hidden when the view opens restored past the top fifth", () => {+ render(<Harness metrics={{ scrollHeight: 4000, clientHeight: 500 }} />);+ const scroller = screen.getByTestId("scroller");+ scroller.scrollTop = 2000;fireEvent.scroll(scroller);flushFrame();expect(screen.queryByRole("button", { name: "latest" })).toBeNull();diff --git a/packages/views/issues/hooks/use-jump-to-latest.ts b/packages/views/issues/hooks/use-jump-to-latest.tsindex ddcfc68236..4696709e90 100644--- a/packages/views/issues/hooks/use-jump-to-latest.ts+++ b/packages/views/issues/hooks/use-jump-to-latest.ts@@ -3,7 +3,7 @@ import { useCallback, useEffect, useRef, useState } from "react";/*** Drives the issue timeline's "Jump to latest" affordance (MUL-8324).*- * `visible` is on while the reader is in the first half of the page and the+ * `visible` is on while the reader is still near the top of the page and the* newest entry is more than one screen away; see `shouldShow`.** `jump` drives scrollTop to the bottom directly instead of asking Virtuoso@@ -98,18 +98,21 @@ export function useJumpToLatest(scrollContainerEl: HTMLElement | null) {}/**- * Show only while the reader is in the first half of the page: what is left- * below the viewport must be more than half of the page, and more than one- * screen. Past the midpoint the latest entry is close enough to scroll to by- * hand, and short pages never show the button at all.+ * Show only near the top of the page: the viewport's top edge must still be+ * within the first `SHOW_WITHIN_TOP_RATIO` of the page, and more than one+ * screen must be left below. Once the reader has scrolled further on their+ * own they are reading, not hunting for the latest entry, so the button gets+ * out of the way; short pages never show it at all.*/function shouldShow(el: HTMLElement) {- const remaining = distanceFromBottom(el);- return remaining > el.clientHeight && remaining > el.scrollHeight * SHOW_REMAINING_RATIO;+ return (+ el.scrollTop <= el.scrollHeight * SHOW_WITHIN_TOP_RATIO &&+ distanceFromBottom(el) > el.clientHeight+ );}-/** Share of the page that must still be below the viewport for the button to show. */-const SHOW_REMAINING_RATIO = 0.5;+/** Share of the page the reader can scroll through before the button hides. */+const SHOW_WITHIN_TOP_RATIO = 0.2;function distanceFromBottom(el: HTMLElement) {return el.scrollHeight - el.scrollTop - el.clientHeight;