Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
feat(web): add a jump-to-latest button to the Room timeline
jeffreyc21fbda80818
diff --git a/apps/web/src/features/rooms/chat/jump-to-latest-button.tsx b/apps/web/src/features/rooms/chat/jump-to-latest-button.tsxnew file mode 100644index 00000000..9ef432e4--- /dev/null+++ b/apps/web/src/features/rooms/chat/jump-to-latest-button.tsx@@ -0,0 +1,36 @@+import { ArrowDown02Icon } from "@hugeicons/core-free-icons";++import { Icon } from "@/components/ui/icon";++/**+ * Floats above the composer while the reader is away from the newest Message.+ * Typing dots replace the arrow while an Agent in the Room is still working, so+ * the reader knows more is arriving below.+ */+export function JumpToLatestButton({+ agentWorking,+ onClick,+}: {+ agentWorking: boolean;+ onClick: () => void;+}) {+ return (+ <button+ aria-label="Jump to latest messages"+ className="app-floating-enter absolute bottom-3 left-1/2 z-10 inline-flex size-9 -translate-x-1/2 items-center justify-center rounded-full border border-border bg-background text-muted-foreground shadow-md transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"+ data-agent-working={agentWorking}+ onClick={onClick}+ type="button"+ >+ {agentWorking ? (+ <span aria-hidden="true" className="town-dots">+ <span />+ <span />+ <span />+ </span>+ ) : (+ <Icon icon={ArrowDown02Icon} size={16} />+ )}+ </button>+ );+}diff --git a/apps/web/src/features/rooms/chat/room-chat-timeline-section.tsx b/apps/web/src/features/rooms/chat/room-chat-timeline-section.tsxindex 7167e8f3..490c8982 100644--- a/apps/web/src/features/rooms/chat/room-chat-timeline-section.tsx+++ b/apps/web/src/features/rooms/chat/room-chat-timeline-section.tsx@@ -1,5 +1,8 @@import type { ComponentProps } from "react";+import { isRunWorking } from "@/features/teamhub/run-status";++import { JumpToLatestButton } from "./jump-to-latest-button";import { MessageTimeline } from "./message-timeline";import type { RoomChatData } from "./use-room-chat-data";import type { RoomChatConversationState } from "./use-room-chat-conversation-state";@@ -45,6 +48,9 @@ export function RoomChatTimelineSection({} = state;return (<RoomTimelineViewport+ agentWorking={conversation.streamingRunStatuses.some(isRunWorking)}+ awayFromLatest={timeline.awayFromLatest}+ onJumpToLatest={timeline.scrollToLatest}actorDisplayNames={actions.actorDisplayNames}canLoadOlder={messages.hasNextPage}currentActorId={currentActorId}@@ -122,29 +128,43 @@ export function RoomChatTimelineSection({}type RoomTimelineViewportProps = ComponentProps<typeof MessageTimeline> & {+ agentWorking: boolean;+ awayFromLatest: boolean;initialScrollReady: boolean;+ onJumpToLatest: () => void;viewportOnScroll: NonNullable<ComponentProps<"div">["onScroll"]>;viewportRef: ComponentProps<"div">["ref"];};function RoomTimelineViewport({+ agentWorking,+ awayFromLatest,initialScrollReady,+ onJumpToLatest,viewportOnScroll,viewportRef,...timelineProps}: RoomTimelineViewportProps) {return (- <div- aria-label="Room timeline"- data-voice-scroll="main"- className={`room-timeline workspace-scrollbar flex flex-1 flex-col overflow-y-scroll [overflow-anchor:none] ${- initialScrollReady ? "" : "invisible"- }`}- data-initial-scroll-ready={initialScrollReady}- onScroll={viewportOnScroll}- ref={viewportRef}- >- <MessageTimeline {...timelineProps} />+ <div className="relative flex min-h-0 flex-1 flex-col">+ <div+ aria-label="Room timeline"+ data-voice-scroll="main"+ className={`room-timeline workspace-scrollbar flex flex-1 flex-col overflow-y-scroll [overflow-anchor:none] ${+ initialScrollReady ? "" : "invisible"+ }`}+ data-initial-scroll-ready={initialScrollReady}+ onScroll={viewportOnScroll}+ ref={viewportRef}+ >+ <MessageTimeline {...timelineProps} />+ </div>+ {awayFromLatest ? (+ <JumpToLatestButton+ agentWorking={agentWorking}+ onClick={onJumpToLatest}+ />+ ) : null}</div>);}diff --git a/apps/web/src/features/rooms/chat/use-room-timeline-scroll.test.tsx b/apps/web/src/features/rooms/chat/use-room-timeline-scroll.test.tsxindex 56efd012..9a472fb8 100644--- a/apps/web/src/features/rooms/chat/use-room-timeline-scroll.test.tsx+++ b/apps/web/src/features/rooms/chat/use-room-timeline-scroll.test.tsx@@ -1,5 +1,5 @@import { fireEvent, render, screen } from "@testing-library/react";-import { afterEach, describe, expect, it, vi } from "vitest";+import { afterEach, describe, expect, it, onTestFinished, vi } from "vitest";import { useRoomTimelineScroll } from "./use-room-timeline-scroll";function Timeline({@@ -45,6 +45,9 @@ function Timeline({>Latest</button>+ {scroll.awayFromLatest ? (+ <button onClick={scroll.scrollToLatest}>Jump to latest</button>+ ) : null}<divaria-label="Room timeline"ref={scroll.timelineRef}@@ -224,6 +227,41 @@ describe("Message deep-link positioning", () => {});});+describe("Jump to latest", () => {+ it("appears away from the newest Message and returns the reader to following", () => {+ let height = 1000;+ vi.spyOn(Element.prototype, "scrollHeight", "get").mockImplementation(+ () => height,+ );+ vi.spyOn(Element.prototype, "clientHeight", "get").mockReturnValue(200);+ // jsdom does not implement element scrolling.+ const scrollTo = vi.fn(function (this: Element, options: ScrollToOptions) {+ this.scrollTop = options.top!;+ fireEvent.scroll(this);+ });+ Object.defineProperty(Element.prototype, "scrollTo", {+ configurable: true,+ value: scrollTo,+ });+ onTestFinished(() => {+ delete (Element.prototype as Partial<Element>).scrollTo;+ });+ const view = render(<Timeline visible />);+ const timeline = screen.getByLabelText("Room timeline");+ expect(screen.queryByText("Jump to latest")).toBeNull();++ timeline.scrollTop = 150;+ fireEvent.scroll(timeline);+ fireEvent.click(screen.getByText("Jump to latest"));++ expect(scrollTo).toHaveBeenCalledWith({ top: 1000, behavior: "smooth" });+ expect(screen.queryByText("Jump to latest")).toBeNull();+ height = 1200;+ view.rerender(<Timeline visible messageCount={11} />);+ expect(timeline.scrollTop).toBe(1200);+ });+});+describe("Room timeline remount", () => {it("restores a Room's reading position on return and isolates other Rooms and Accounts", () => {vi.spyOn(Element.prototype, "scrollHeight", "get").mockReturnValue(1000);diff --git a/apps/web/src/features/rooms/chat/use-room-timeline-scroll.ts b/apps/web/src/features/rooms/chat/use-room-timeline-scroll.tsindex d3d73f8a..58701062 100644--- a/apps/web/src/features/rooms/chat/use-room-timeline-scroll.ts+++ b/apps/web/src/features/rooms/chat/use-room-timeline-scroll.ts@@ -60,6 +60,7 @@ export function useRoomTimelineScroll({);const previousTimelineRef = useRef<HTMLDivElement | null>(null);const [initialScrollReady, setInitialScrollReady] = useState(false);+ const [awayFromLatest, setAwayFromLatest] = useState(false);const shouldAutoFollowRef = useRef(true);const pendingPrependRef = useRef<PendingPrepend | null>(null);const readingAnchorRef = useRef<ReadingAnchor | null>(null);@@ -226,6 +227,7 @@ export function useRoomTimelineScroll({function recordTimelineScroll(timeline: HTMLDivElement) {const corrected = correctedScrollTopRef.current === timeline.scrollTop;correctedScrollTopRef.current = null;+ setAwayFromLatest(!isNearTimelineBottom(timeline));if (!corrected) {shouldAutoFollowRef.current = isNearTimelineBottom(timeline);readingAnchorRef.current = shouldAutoFollowRef.current@@ -249,6 +251,15 @@ export function useRoomTimelineScroll({shouldAutoFollowRef.current = true;}+ function scrollToLatest() {+ const timeline = timelineElement;+ if (!timeline) {+ return;+ }+ shouldAutoFollowRef.current = true;+ timeline.scrollTo({ top: timeline.scrollHeight, behavior: "smooth" });+ }+/** Whether the reader follows the newest Message rather than history. */function isFollowingLatest() {return (@@ -259,12 +270,14 @@ export function useRoomTimelineScroll({}return {+ awayFromLatest,cancelOlderMessagesIfUnchanged,initialScrollReady,isFollowingLatest,pinToLatest,prepareForOlderMessages,recordTimelineScroll,+ scrollToLatest,timelineElement,timelineRef: setTimelineElement,};