@devries-cameron20 / t3code Mirror · read-only / commits / 1f45f14ae8
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 13:30 UTC

fix(web): queued images open in the image viewer (#33298)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

OpeOginni committed Nov 14, 2026 at 18:29 UTC 1f45f14ae865f6e199a36328bb088d36960cf77c
4 files changed +165 -51
apps/mobile/src/features/threads/ThreadQueueControl.tsx
+61 -17
@@ -25,6 +25,7 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
25
26 import { Button } from "../../components/ui/Button";
27 import * as Dialog from "../../components/ui/Dialog";
28 +import { FilePreviewModal, type FilePreviewSource } from "../../components/ui/FilePreviewModal";
29 import { SheetHeader } from "../../components/ui/SheetHeader";
30 import { AppText as Text } from "../../components/ui/AppText";
31 import { SymbolView } from "../../components/ui/AppSymbol";
@@ -143,6 +144,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
144 });
145 const [resuming, setResuming] = useState(false);
146 const [busyRunId, setBusyRunId] = useState<RunId | null>(null);
147 + const [previewFile, setPreviewFile] = useState<FilePreviewSource | null>(null);
148 const busyRef = useRef(false);
149 const queuedRuns = workflow?.queuedRuns ?? [];
150
@@ -321,6 +323,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
323 <QueueAttachmentThumbnails
324 environmentId={target.environmentId}
325 attachments={attachments}
326 + onPressPreview={setPreviewFile}
327 />
328 <View className="min-w-0 flex-1 gap-0.5">
329 {message ? (
@@ -384,6 +387,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
387 <SheetHeader title="Queued" onClose={() => navigation.goBack()} />
388 <ScreenContent>{content}</ScreenContent>
389 </View>
390 + <FilePreviewModal source={previewFile} onRequestClose={() => setPreviewFile(null)} />
391 </GestureHandlerRootView>
392 );
393 }
@@ -436,8 +440,10 @@ function QueueRowSwipeable(props: {
440 function QueueAttachmentThumbnails(props: {
441 readonly environmentId: EnvironmentId;
442 readonly attachments: ReadonlyArray<ChatAttachment>;
443 + readonly onPressPreview: (source: FilePreviewSource) => void;
444 }) {
445 const images = props.attachments.filter((attachment) => attachment.mimeType.startsWith("image/"));
446 + const gallery = images.map((attachment) => queueImagePreview(props.environmentId, attachment));
447 const shown = images.slice(0, THUMBNAIL_LIMIT);
448 const overflow = props.attachments.length - shown.length;
449 if (props.attachments.length === 0) return null;
@@ -448,6 +454,12 @@ function QueueAttachmentThumbnails(props: {
454 key={attachment.id}
455 environmentId={props.environmentId}
456 attachment={attachment}
457 + onPress={() =>
458 + props.onPressPreview({
459 + ...queueImagePreview(props.environmentId, attachment),
460 + gallery,
461 + })
462 + }
463 />
464 ))}
465 {overflow > 0 ? (
@@ -461,28 +473,60 @@ function QueueAttachmentThumbnails(props: {
473 );
474 }
475
476 +function queueAttachmentResource(attachment: ChatAttachment) {
477 + return {
478 + _tag: "attachment",
479 + attachmentId: attachment.id,
480 + fileName: attachment.name,
481 + mimeType: attachment.mimeType,
482 + disposition: "inline",
483 + } as const;
484 +}
485 +
486 +function queueImagePreview(environmentId: EnvironmentId, attachment: ChatAttachment) {
487 + const resource = queueAttachmentResource(attachment);
488 + return {
489 + kind: "image",
490 + environmentId,
491 + resource,
492 + name: attachment.name,
493 + mimeType: attachment.mimeType,
494 + actionsSource: {
495 + name: attachment.name,
496 + mimeType: attachment.mimeType,
497 + environmentId,
498 + resource,
499 + },
500 + } as const;
501 +}
502 +
503 function QueueAttachmentThumbnail(props: {
504 readonly environmentId: EnvironmentId;
505 readonly attachment: ChatAttachment;
506 + readonly onPress: () => void;
507 }) {
468 - const resource = {
469 - _tag: "attachment",
470 - attachmentId: props.attachment.id,
471 - fileName: props.attachment.name,
472 - mimeType: props.attachment.mimeType,
473 - disposition: "inline",
474 - } as const;
508 + const resource = queueAttachmentResource(props.attachment);
509 const url = useAssetUrl(props.environmentId, resource);
476 - if (url === null) {
477 - return <View className="h-6 w-6 rounded bg-subtle" />;
478 - }
510 return (
480 - <Image
481 - source={assetImageSource(props.environmentId, resource, url)}
482 - cachePolicy="memory-disk"
483 - contentFit="cover"
484 - style={{ width: 24, height: 24, borderRadius: 4 }}
485 - accessibilityIgnoresInvertColors
486 - />
511 + // Its own press target, so tapping an image previews it instead of editing the message.
512 + <Pressable
513 + accessibilityRole="imagebutton"
514 + accessibilityLabel={`Open ${props.attachment.name}`}
515 + hitSlop={6}
516 + onPress={props.onPress}
517 + className="active:opacity-70"
518 + >
519 + {url === null ? (
520 + <View className="h-6 w-6 rounded bg-subtle" />
521 + ) : (
522 + <Image
523 + source={assetImageSource(props.environmentId, resource, url)}
524 + cachePolicy="memory-disk"
525 + contentFit="cover"
526 + style={{ width: 24, height: 24, borderRadius: 4 }}
527 + accessibilityIgnoresInvertColors
528 + />
529 + )}
530 + </Pressable>
531 );
532 }
apps/web/src/components/ChatView.tsx
+5 -4
@@ -3049,6 +3049,10 @@ export default function ChatView(props: ChatViewProps) {
3049 .some((id) => id !== "" && !previousIds.has(id));
3050 if (hasNewMessage && timelineLiveFollowEnabled) scrollToEnd(true);
3051 }, [routeThreadKey, pendingGuestMessageKey, timelineLiveFollowEnabled, scrollToEnd]);
3052 + const onExpandTimelineImage = (preview: ExpandedImagePreview) => {
3053 + openExpandedImagePreview(routeThreadKey, preview);
3054 + };
3055 + const onExpandTimelineImageStable = useStableCallback(onExpandTimelineImage);
3056 const queuedRunsControl =
3057 isServerThread && activeThread ? (
3058 <>
@@ -3071,6 +3075,7 @@ export default function ChatView(props: ChatViewProps) {
3075 onCancelEdit={queuedRunEdit.cancelEdit}
3076 timestampFormat={timestampFormat}
3077 onOpenThread={onOpenRelatedThreadStable}
3078 + onImageExpand={onExpandTimelineImageStable}
3079 />
3080 </>
3081 ) : null;
@@ -3116,10 +3121,6 @@ export default function ChatView(props: ChatViewProps) {
3121 workLocallyResendReady,
3122 ]);
3123
3119 - const onExpandTimelineImage = (preview: ExpandedImagePreview) => {
3120 - openExpandedImagePreview(routeThreadKey, preview);
3121 - };
3122 - const onExpandTimelineImageStable = useStableCallback(onExpandTimelineImage);
3124 const shownThreadSyncPhase = activeEnvironmentUnavailable ? null : delayedThreadSyncPhase;
3125 const hasThreadNow =
3126 attentionNow !== null || workNow !== null || goalNow !== null || shownThreadSyncPhase !== null;
apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx
+69 -1
@@ -9,7 +9,7 @@ import {
9 import * as DateTime from "effect/DateTime";
10 import * as Option from "effect/Option";
11 import { AsyncResult, type Atom, AtomRegistry } from "effect/reactivity";
12 -import { Profiler, type ComponentProps } from "react";
12 +import { Profiler, useState, type ComponentProps } from "react";
13 import { expect, it, vi } from "vite-plus/test";
14 import { page } from "vite-plus/test/browser";
15
@@ -81,6 +81,8 @@ import { EMPTY_ENVIRONMENT_THREAD_STATE } from "@t3tools/client-runtime/state/th
81 import { act, render as renderUi } from "../../../test/render";
82 import { makeStreamingTimelineFixture, makeThreadProjectionFixture } from "../../test-fixtures";
83 import { QueuedRunsControl } from "./QueuedRunsControl";
84 +import { ExpandedImageDialog } from "./ExpandedImageDialog";
85 +import type { ExpandedImagePreview } from "./ExpandedImagePreview";
86
87 function setup() {
88 state.workflow = null;
@@ -96,12 +98,78 @@ const baseProps = {
98 onCancelEdit: () => undefined,
99 timestampFormat: "locale",
100 onOpenThread: () => undefined,
101 + onImageExpand: () => undefined,
102 } satisfies ComponentProps<typeof QueuedRunsControl>;
103
104 async function renderQueue(props: Partial<ComponentProps<typeof QueuedRunsControl>> = {}) {
105 return renderUi(<QueuedRunsControl {...baseProps} {...props} />);
106 }
107
108 +it.each([false, true])(
109 + "opens queued images in the existing gallery, pending=%s",
110 + async (pending) => {
111 + setup();
112 + const attachments = ["first.png", "second.png"].map((name) => ({
113 + type: "image" as const,
114 + id: name,
115 + name,
116 + mimeType: "image/png",
117 + sizeBytes: 128,
118 + }));
119 + state.workflow = {
120 + activeRun: null,
121 + queuedRuns: pending
122 + ? []
123 + : [
124 + {
125 + run: { id: "run:queued", userMessageId: "message:queued" },
126 + text: "Later",
127 + attachments,
128 + },
129 + ],
130 + };
131 + function QueueWithGallery() {
132 + const [preview, setPreview] = useState<ExpandedImagePreview | null>(null);
133 + return (
134 + <>
135 + <QueuedRunsControl
136 + {...baseProps}
137 + optimisticMessages={
138 + pending
139 + ? [
140 + {
141 + id: MessageId.make("message:pending"),
142 + inputIntent: "queued_turn",
143 + text: "Later",
144 + attachments: attachments.map((attachment) => ({
145 + ...attachment,
146 + previewUrl: `https://assets.test/${attachment.id}`,
147 + })),
148 + },
149 + ]
150 + : []
151 + }
152 + onImageExpand={setPreview}
153 + />
154 + {preview ? (
155 + <ExpandedImageDialog preview={preview} onClose={() => setPreview(null)} />
156 + ) : null}
157 + </>
158 + );
159 + }
160 + await using _screen = await renderUi(<QueueWithGallery />);
161 +
162 + await page.getByRole("button", { name: "Preview second.png", exact: true }).click();
163 + await expect.element(page.getByRole("dialog")).toBeVisible();
164 + await expect.element(page.getByText("second.png (2/2)", { exact: true })).toBeVisible();
165 + await page.getByRole("button", { name: "Previous media", exact: true }).click();
166 + await expect.element(page.getByText("first.png (1/2)", { exact: true })).toBeVisible();
167 + await page.getByRole("button", { name: "Close image preview", exact: true }).click();
168 + await expect.element(page.getByRole("dialog")).not.toBeInTheDocument();
169 + await expect.element(page.getByText("Later", { exact: true })).toBeVisible();
170 + },
171 +);
172 +
173 it("previews assistant quotes as readable text and preserves the citation when editing", async () => {
174 setup();
175 const quotedText = "Cache the parsed config per worktree.";
apps/web/src/components/chat/QueuedRunsControl.tsx
+30 -29
@@ -31,7 +31,7 @@ import { threadEnvironment } from "../../state/threads";
31 import { useQuietThreadProjection, useQuietThreadShell } from "../../state/entities";
32 import { useEnvironment } from "../../state/environments";
33 import { useAtomCommand } from "../../state/use-atom-command";
34 -import { isImageAttachment, type ChatMessage } from "../../types";
34 +import { isImageAttachment, type ChatImageAttachment, type ChatMessage } from "../../types";
35 import { cn } from "~/lib/utils";
36 import { Button, InlineButton } from "../ui/button";
37 import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
@@ -39,6 +39,7 @@ import type { TimestampFormat } from "@t3tools/contracts/settings";
39 import { GuestMessageName } from "./guestMessageStyle";
40 import { TimelineRowTimestamp } from "./TimelineRowParts";
41 import { FoldedMessageHeader, useScheduledTaskTitle } from "./TimelineUserMessageRow";
42 +import { buildExpandedImagePreview, type ExpandedImagePreview } from "./ExpandedImagePreview";
43
44 export interface EditQueuedRunRequest {
45 readonly runId: RunId;
@@ -47,12 +48,6 @@ export interface EditQueuedRunRequest {
48 readonly attachments: ReadonlyArray<ContractChatAttachment>;
49 }
50
50 -interface QueuedRowThumbnail {
51 - readonly key: string;
52 - readonly name: string;
53 - readonly url: string | null;
54 -}
55 -
51 // A longer queue shows its first messages and a button that shows the rest.
52 const QUEUE_VISIBLE_ROWS = 3;
53
@@ -67,7 +62,7 @@ function queuedImageResources(projection: ThreadQueueProjection | undefined) {
62 if (!projection) return [];
63 return deriveThreadQueueWorkflowState(projection).queuedRuns.flatMap(({ attachments }) =>
64 attachments.flatMap((attachment) =>
70 - attachment.type === "image"
65 + isImageAttachment(attachment)
66 ? [{ _tag: "attachment" as const, attachmentId: attachment.id }]
67 : [],
68 ),
@@ -93,6 +88,7 @@ export function QueuedRunsControl({
88 readonly onCancelEdit: () => void;
89 readonly timestampFormat: TimestampFormat;
90 readonly onOpenThread: (threadId: ThreadId, environmentId?: EnvironmentId) => void;
91 + readonly onImageExpand: (preview: ExpandedImagePreview) => void;
92 }) {
93 const projection = useQuietThreadProjection(
94 scopeThreadRef(props.environmentId, props.threadId),
@@ -140,13 +136,14 @@ export function QueuedRunsControl({
136 // A guest's message keeps the guest's words; the owner can cancel it, not rewrite it.
137 editable: context?.guest === undefined,
138 attachments,
143 - thumbnails: attachments
144 - .filter((attachment) => attachment.type === "image")
145 - .map<QueuedRowThumbnail>((attachment) => ({
146 - key: attachment.id,
147 - name: attachment.name,
148 - url: queuedImageUrlById.get(attachment.id) ?? null,
149 - })),
139 + thumbnails: attachments.filter(isImageAttachment).map<ChatImageAttachment>((attachment) => {
140 + const previewUrl = queuedImageUrlById.get(attachment.id);
141 + return {
142 + ...attachment,
143 + type: "image",
144 + ...(previewUrl ? { previewUrl } : {}),
145 + };
146 + }),
147 pending: false,
148 })),
149 ...optimisticQueued.map((message) => ({
@@ -159,13 +156,7 @@ export function QueuedRunsControl({
156 text: message.text,
157 editable: true,
158 attachments: [] as ReadonlyArray<ContractChatAttachment>,
162 - thumbnails: (message.attachments ?? [])
163 - .filter(isImageAttachment)
164 - .map<QueuedRowThumbnail>((attachment) => ({
165 - key: attachment.id,
166 - name: attachment.name,
167 - url: attachment.previewUrl ?? null,
168 - })),
159 + thumbnails: (message.attachments ?? []).filter(isImageAttachment),
160 pending: true,
161 })),
162 ];
@@ -273,6 +264,7 @@ export function QueuedRunsControl({
264 isEditing={isEditing}
265 timestampFormat={props.timestampFormat}
266 onOpenThread={props.onOpenThread}
267 + onImageExpand={props.onImageExpand}
268 >
269 {canSendRun(item.freshContext) && !isEditing ? (
270 <>
@@ -407,11 +399,12 @@ function QueuedMessage(props: {
399 readonly environmentId: EnvironmentId;
400 readonly message: QueuedRunMessage | undefined;
401 readonly previewText: string;
410 - readonly thumbnails: ReadonlyArray<QueuedRowThumbnail>;
402 + readonly thumbnails: ReadonlyArray<ChatImageAttachment>;
403 readonly isEditing: boolean;
404 readonly timestampFormat: TimestampFormat;
405 readonly onOpenThread: (threadId: ThreadId, environmentId?: EnvironmentId) => void;
406 readonly children: ReactNode;
407 + readonly onImageExpand: (preview: ExpandedImagePreview) => void;
408 }) {
409 const presentation = props.message ? resolveUserMessagePresentation(props.message) : null;
410 const attribution = presentation?.attribution ?? null;
@@ -484,20 +477,28 @@ function QueuedMessage(props: {
477 {props.thumbnails.length > 0 ? (
478 <span className="flex flex-wrap items-center gap-1">
479 {props.thumbnails.map((thumbnail) => (
487 - <span
488 - key={thumbnail.key}
489 - className="size-8 overflow-hidden rounded-md border border-border/70 bg-background"
480 + <button
481 + key={thumbnail.id}
482 + type="button"
483 + aria-label={`Preview ${thumbnail.name}`}
484 + disabled={!thumbnail.previewUrl}
485 + className="size-8 overflow-hidden rounded-md border border-border/70 bg-background enabled:cursor-zoom-in"
486 + onPointerDown={(event) => event.preventDefault()}
487 + onClick={() => {
488 + const preview = buildExpandedImagePreview(props.thumbnails, thumbnail.id);
489 + if (preview) props.onImageExpand(preview);
490 + }}
491 >
491 - {thumbnail.url ? (
492 + {thumbnail.previewUrl ? (
493 <img
493 - src={thumbnail.url}
494 + src={thumbnail.previewUrl}
495 alt={thumbnail.name}
496 className="size-full object-cover"
497 />
498 ) : (
499 <span aria-label={thumbnail.name} className="block size-full bg-muted/60" />
500 )}
500 - </span>
501 + </button>
502 ))}
503 </span>
504 ) : null}