Skip to content

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.

refactor(web): fold Task input bubbles with Mantine Spoiler

LeoXing5943045715b6
diff --git a/apps/web/src/features/rooms/task-sidebar/adapters/task-input-bubble.test.tsx b/apps/web/src/features/rooms/task-sidebar/adapters/task-input-bubble.test.tsx
index 675c58dc..f7c7fabe 100644
--- a/apps/web/src/features/rooms/task-sidebar/adapters/task-input-bubble.test.tsx
+++ b/apps/web/src/features/rooms/task-sidebar/adapters/task-input-bubble.test.tsx
@@ -1,60 +1,75 @@
-import { fireEvent, render, screen } from "@testing-library/react";
-import { afterEach, describe, expect, it } from "vitest";
+import { act, fireEvent, render, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
import { TaskInputBubble } from "./task-input-bubble";
-const heights = Object.getOwnPropertyDescriptor(
- HTMLElement.prototype,
- "scrollHeight",
-);
-
afterEach(() => {
- if (heights)
- Object.defineProperty(HTMLElement.prototype, "scrollHeight", heights);
- else Reflect.deleteProperty(HTMLElement.prototype, "scrollHeight");
+ vi.unstubAllGlobals();
});
-function contentOverflows() {
- Object.defineProperty(HTMLElement.prototype, "scrollHeight", {
- configurable: true,
- get: () => 400,
- });
+/** jsdom has no layout; every observed element reports this height. */
+function measureContent(height: number) {
+ vi.stubGlobal(
+ "ResizeObserver",
+ class {
+ #callback: ResizeObserverCallback;
+ constructor(callback: ResizeObserverCallback) {
+ this.#callback = callback;
+ }
+ observe(target: Element) {
+ this.#callback(
+ [
+ {
+ contentRect: { height, width: 320 },
+ target,
+ } as ResizeObserverEntry,
+ ],
+ this,
+ );
+ }
+ disconnect() {}
+ unobserve() {}
+ },
+ );
}
describe("TaskInputBubble", () => {
- it("shows a short input whole, without a fold", () => {
+ it("shows an input that fits whole, without a fold", async () => {
+ measureContent(22);
render(<TaskInputBubble authorKind="agent" body="Add a closing letter." />);
+ await act(() => new Promise(requestAnimationFrame));
expect(screen.getByText("Add a closing letter.")).toBeVisible();
expect(screen.queryByRole("button")).not.toBeInTheDocument();
});
- it("folds a long input to its first lines and opens it in place", () => {
- contentOverflows();
+ it("folds a long input to its first lines and opens it in place", async () => {
+ measureContent(400);
render(
<TaskInputBubble
authorKind="agent"
body={"Write the report.\n\n1. Opening\n2. Events\n3. Finances"}
/>,
);
- const content = screen
- .getByText("Write the report.")
- .closest(".message-markdown")!.parentElement!;
- const more = screen.getByRole("button", { name: "Show more" });
+ const more = await screen.findByRole("button", { name: "Show more" });
expect(more).toHaveAttribute("aria-expanded", "false");
- expect(content).toHaveClass("max-h-[110px]", "overflow-hidden");
+ const region = document.getElementById(more.getAttribute("aria-controls")!);
+ expect(region).toHaveTextContent("Finances");
+ expect(region!.className).toContain("mask-image");
fireEvent.click(more);
- const less = screen.getByRole("button", { name: "Show less" });
- expect(less).toHaveAttribute("aria-expanded", "true");
- expect(content).not.toHaveClass("max-h-[110px]");
+ expect(screen.getByRole("button", { name: "Show less" })).toHaveAttribute(
+ "aria-expanded",
+ "true",
+ );
+ expect(region!.className).not.toContain("mask-image");
- fireEvent.click(less);
+ fireEvent.click(screen.getByRole("button", { name: "Show less" }));
expect(screen.getByRole("button", { name: "Show more" })).toBeVisible();
- expect(content).toHaveClass("max-h-[110px]");
+ expect(region!.className).toContain("mask-image");
});
it("caps the width on a wrapper, since the bubble's own max-width outranks utilities", () => {
diff --git a/apps/web/src/features/rooms/task-sidebar/adapters/task-input-bubble.tsx b/apps/web/src/features/rooms/task-sidebar/adapters/task-input-bubble.tsx
index 05cec041..b29ea13c 100644
--- a/apps/web/src/features/rooms/task-sidebar/adapters/task-input-bubble.tsx
+++ b/apps/web/src/features/rooms/task-sidebar/adapters/task-input-bubble.tsx
@@ -1,11 +1,15 @@
import { ArrowDown01Icon } from "@hugeicons/core-free-icons";
-import { useLayoutEffect, useRef, useState } from "react";
+import { HeadlessMantineProvider, Spoiler } from "@mantine/core";
+import { useState } from "react";
import { Icon } from "@/components/ui/icon";
import { cn } from "@/lib/cn";
import { MessageMarkdown } from "../../chat/message-markdown";
+/** About four lines of message text. */
+const FOLDED_HEIGHT = 110;
+
/**
* A brief or follow-up sent to a Task, on the right like a Room message. A
* long one folds to its first few lines so the AlterEgo's work stays in view.
@@ -17,53 +21,48 @@ export function TaskInputBubble({
authorKind: "agent" | "human";
body: string;
}) {
- const content = useRef<HTMLDivElement>(null);
const [expanded, setExpanded] = useState(false);
- const [clipped, setClipped] = useState(false);
- useLayoutEffect(() => {
- const node = content.current;
- if (!node || expanded) return;
- const measure = () => setClipped(node.scrollHeight > node.clientHeight + 1);
- measure();
- if (typeof ResizeObserver === "undefined") return;
- const observer = new ResizeObserver(measure);
- observer.observe(node);
- return () => observer.disconnect();
- }, [body, expanded]);
return (
<div className="flex justify-end">
{/* The bubble's own max-width outranks a width utility on it. */}
<div className="min-w-0 max-w-[85%]">
<div className="room-message-bubble">
- <div
- className={cn(
- !expanded && "max-h-[110px] overflow-hidden",
- !expanded &&
- clipped &&
- "[mask-image:linear-gradient(to_bottom,black_calc(100%-28px),transparent)]",
- )}
- ref={content}
- >
- <MessageMarkdown authorKind={authorKind} body={body} />
- </div>
- {clipped || expanded ? (
- <button
- aria-expanded={expanded}
- className="-mx-1 mt-1 inline-flex items-center gap-1 rounded-md px-1 text-xs font-medium text-muted-foreground transition-colors duration-150 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
- onClick={() => setExpanded((value) => !value)}
- type="button"
+ {/* Spoiler owns measurement, resize updates and the toggle's ARIA. */}
+ <HeadlessMantineProvider>
+ <Spoiler
+ className="group/fold flex min-w-0 flex-col items-start [--mantine-scale:1]"
+ classNames={{
+ content: cn(
+ "order-first w-full overflow-hidden",
+ !expanded &&
+ "group-data-[has-spoiler]/fold:[mask-image:linear-gradient(to_bottom,black_calc(100%-28px),transparent)]",
+ ),
+ control:
+ "-mx-1 mt-1 inline-flex items-center gap-1 rounded-md px-1 text-xs font-medium text-muted-foreground transition-colors duration-150 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
+ }}
+ expanded={expanded}
+ hideLabel={
+ <>
+ Show less
+ <Icon
+ className="rotate-180"
+ icon={ArrowDown01Icon}
+ size={14}
+ />
+ </>
+ }
+ maxHeight={FOLDED_HEIGHT}
+ onExpandedChange={setExpanded}
+ showLabel={
+ <>
+ Show more
+ <Icon icon={ArrowDown01Icon} size={14} />
+ </>
+ }
>
- {expanded ? "Show less" : "Show more"}
- <Icon
- className={cn(
- "transition-transform duration-150",
- expanded && "rotate-180",
- )}
- icon={ArrowDown01Icon}
- size={14}
- />
- </button>
- ) : null}
+ <MessageMarkdown authorKind={authorKind} body={body} />
+ </Spoiler>
+ </HeadlessMantineProvider>
</div>
</div>
</div>