Skip to content

Commit 777849c

Browse files
t3dotggclaude
andcommitted
fix(web): arrow through the images an agent viewed
The viewed-images row was not marked as a gallery, so each image opened alone and the preview had no previous or next. Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent 5da53f8 commit 777849c

2 files changed

Lines changed: 46 additions & 6 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.browser.test.tsx‎

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ import {
4242
type PendingApproval,
4343
deriveTimelineEntriesFromVisibleTurnItems,
4444
} from "../../session-logic";
45+
import { ViewedImagesTimelineRow } from "./TimelineWorkEntryRow";
4546
import { remarkThoughtPreview } from "./TimelineWorkEntryRow.logic";
47+
import { TimelineRowCtx } from "./timelineRowContext";
4648
import { parseMarkdownWithMath } from "@t3tools/shared/markdownMath";
4749
import { collectThreadFindRanges } from "./threadFindHighlights";
4850
import { toastManager } from "../ui/toast";
@@ -72,14 +74,14 @@ vi.mock(import("~/state/query"), async (original) => ({
7274
})) as never,
7375
}));
7476

75-
const audioAsset = vi.hoisted(() => ({ url: "" }));
77+
const stubbedAsset = vi.hoisted(() => ({ url: "" }));
7678
vi.mock(import("~/assets/assetUrls"), async (original) => {
7779
const actual = await original();
7880
return {
7981
...actual,
8082
useAssetUrlState: ((...args: Parameters<typeof actual.useAssetUrlState>) =>
81-
audioAsset.url
82-
? { _tag: "Success", url: audioAsset.url }
83+
stubbedAsset.url
84+
? { _tag: "Success", url: stubbedAsset.url }
8385
: actual.useAssetUrlState(...args)) as typeof actual.useAssetUrlState,
8486
};
8587
});
@@ -1240,9 +1242,9 @@ describe("MessagesTimeline attachments", () => {
12401242
);
12411243
const src =
12421244
"data:audio/wav;base64,UklGRiUAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQEAAACA";
1243-
audioAsset.url = src;
1245+
stubbedAsset.url = src;
12441246
onTestFinished(() => {
1245-
audioAsset.url = "";
1247+
stubbedAsset.url = "";
12461248
});
12471249
const props = baseProps();
12481250
await using screen = await renderTimeline(
@@ -1310,6 +1312,44 @@ describe("MessagesTimeline attachments", () => {
13101312
});
13111313
await vi.waitFor(() => expect(one!.isConnected).toBe(false));
13121314
});
1315+
1316+
it("opens a viewed image as a gallery of the images beside it", async () => {
1317+
stubbedAsset.url =
1318+
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
1319+
onTestFinished(() => {
1320+
stubbedAsset.url = "";
1321+
});
1322+
const onImageExpand = vi.fn<ComponentProps<typeof MessagesTimeline>["onImageExpand"]>();
1323+
await using screen = await renderElement(
1324+
<TimelineRowCtx
1325+
value={
1326+
{
1327+
threadRef: { environmentId: ENVIRONMENT_ID, threadId: ThreadId.make("thread-1") },
1328+
workspaceRoot: "/repo",
1329+
onImageExpand,
1330+
} as never
1331+
}
1332+
>
1333+
<ViewedImagesTimelineRow
1334+
row={{
1335+
kind: "viewed-images",
1336+
id: "viewed",
1337+
createdAt: CREATED_AT,
1338+
paths: ["/repo/first.png", "/repo/second.png", "/repo/third.png"],
1339+
}}
1340+
/>
1341+
</TimelineRowCtx>,
1342+
);
1343+
await screen.getByRole("button", { name: "Preview second.png" }).click();
1344+
expect(onImageExpand).toHaveBeenCalledExactlyOnceWith(
1345+
expect.objectContaining({
1346+
index: 1,
1347+
images: ["first.png", "second.png", "third.png"].map((name) =>
1348+
expect.objectContaining({ name }),
1349+
),
1350+
}),
1351+
);
1352+
});
13131353
});
13141354

13151355
describe("MessagesTimeline thread find", () => {

‎apps/web/src/components/chat/TimelineWorkEntryRow.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export function ViewedImagesTimelineRow({
180180
const { threadRef, workspaceRoot, onImageExpand } = use(TimelineRowCtx);
181181
if (!threadRef) return null;
182182
return (
183-
<div className="flex flex-wrap items-start gap-2 px-0.5">
183+
<div className="flex flex-wrap items-start gap-2 px-0.5" data-image-gallery>
184184
{row.paths.map((path) => {
185185
const image = resolveViewedImageAsset(path, {
186186
threadId: threadRef.threadId,

0 commit comments

Comments
 (0)