The best way to control Claude Code, Codex and more from any computer or phone
refactor(web): resting image previews and queued attachments are their own components (#22719)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 21, 2026 at 01:24 UTC
9576c45334259f43d0d4bffa68e8d5d47114e661
2 files changed
+145
-117
apps/web/src/components/chat/ChatComposer.tsx
+24
-117
@@ -158,12 +158,7 @@ import {
158
type ComposerBannerStackContent,
159
type ComposerBannerStackItem,
160
} from "./ComposerBannerStack";
161
-import {
162
- compressImageForStash,
163
- isHeicImageFile,
164
- prepareImageForAttachment,
165
-} from "../../lib/imageCompression";
166
-import { AttachmentImage } from "../media/AttachmentImage";
161
+import { compressImageForStash, prepareImageForAttachment } from "../../lib/imageCompression";
162
import {
163
fileAttachmentTooLargeMessage,
164
formatAttachmentSize,
@@ -201,7 +196,6 @@ import {
196
toKindScopedComposerContextId,
197
} from "@t3tools/shared/composerContextReferences";
198
import {
204
- getRestingComposerImagePreviewCounts,
199
resolveRestingComposerControlsLayout,
200
shouldAnimateComposerRestingTransition,
201
shouldUseCompactComposerPrimaryActions,
@@ -286,11 +280,12 @@ import {
280
} from "./ComposerCommandMenu";
281
import { ComposerPendingApprovalActions } from "./ComposerPendingApprovalActions";
282
import { CompactComposerControlsMenu } from "./CompactComposerControlsMenu";
289
-import { ComposerImageThumbnail } from "./ComposerImageThumbnail";
283
import {
284
ComposerAttachmentFileList,
285
ComposerAttachmentMediaRow,
286
ComposerFilePreviewDialog,
287
+ ComposerQueuedAttachmentRow,
288
+ ComposerRestingImagePreviews,
289
} from "./ComposerAttachmentStrip";
290
import { ComposerPrimaryActions } from "./ComposerPrimaryActions";
291
import { ComposerPendingApprovalPanel } from "./ComposerPendingApprovalPanel";
@@ -344,7 +339,6 @@ import {
339
submitComposerDraft,
340
} from "./composerSubmission";
341
import { ComposerPromptLengthValidation } from "./ComposerPromptLengthValidation";
347
-import { PierreEntryIcon } from "./PierreEntryIcon";
342
import { pendingDraftWork } from "./pendingDraftWork";
343
import {
344
importComposerThreadAttachment,
@@ -989,7 +983,6 @@ import {
983
PencilRulerIcon,
984
PlayIcon,
985
ShieldIcon,
992
- XIcon,
986
} from "lucide-react";
987
import { proposedPlanTitle } from "@t3tools/shared/proposedPlanText";
988
import { hasProviderSetup } from "./ProviderStatusBanner";
@@ -4830,85 +4823,24 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
4823
measure();
4824
return observeResize(restingActionsElement, measure);
4825
}, [isComposerResting, restingActionsElement]);
4833
- const restingImagePreviewCounts = getRestingComposerImagePreviewCounts(
4834
- standaloneComposerImages.length,
4835
- );
4836
- const restingComposerImages = standaloneComposerImages.slice(
4837
- 0,
4838
- restingImagePreviewCounts.visibleCount,
4839
- );
4826
+ const showMoreRestingImages = () => {
4827
+ if (isComposerCollapsedMobile) {
4828
+ expandMobileComposer();
4829
+ return;
4830
+ }
4831
+ setIsComposerScrollCollapsed(false);
4832
+ setIsComposerFocused(true);
4833
+ scheduleComposerFocus();
4834
+ };
4835
const collapsedComposerImagePreviews =
4841
- restingComposerImages.length > 0 ? (
4842
- <div
4843
- data-chat-composer-resting-images="true"
4844
- className="flex shrink-0 items-center gap-1 ps-1"
4845
- >
4846
- {restingComposerImages.map((image) => (
4847
- <button
4848
- key={image.id}
4849
- type="button"
4850
- className="relative size-7 shrink-0 cursor-zoom-in overflow-hidden rounded-md border border-border/70 bg-muted/60"
4851
- aria-label={`Preview ${image.name}`}
4852
- onPointerDown={(event) => event.preventDefault()}
4853
- onClick={() => {
4854
- const preview = buildExpandedImagePreview(composerImages, image.id);
4855
- if (preview) onExpandImage(preview);
4856
- }}
4857
- >
4858
- {image.previewUrl ? (
4859
- <ComposerImageThumbnail
4860
- file={image.file}
4861
- alt=""
4862
- className="size-full object-cover"
4863
- fallback={
4864
- isHeicImageFile({ name: image.name, type: image.mimeType }) ? (
4865
- <AttachmentImage
4866
- name={image.name}
4867
- mimeType={image.mimeType}
4868
- src={image.previewUrl}
4869
- alt=""
4870
- className="size-full object-cover"
4871
- />
4872
- ) : (
4873
- <PierreEntryIcon
4874
- pathValue={image.name}
4875
- kind="file"
4876
- theme={resolvedTheme}
4877
- className="m-auto size-3.5"
4878
- />
4879
- )
4880
- }
4881
- />
4882
- ) : (
4883
- <PierreEntryIcon
4884
- pathValue={image.name}
4885
- kind="file"
4886
- theme={resolvedTheme}
4887
- className="m-auto size-3.5"
4888
- />
4889
- )}
4890
- </button>
4891
- ))}
4892
- {restingImagePreviewCounts.overflowCount > 0 ? (
4893
- <button
4894
- type="button"
4895
- className="flex size-7 shrink-0 cursor-pointer items-center justify-center rounded-md border border-border/70 bg-muted/60 font-medium text-secondary-label text-xs tabular-nums outline-none hover:bg-muted focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background"
4896
- aria-label={`Show ${String(restingImagePreviewCounts.overflowCount)} more image attachments`}
4897
- onPointerDown={(event) => event.preventDefault()}
4898
- onClick={() => {
4899
- if (isComposerCollapsedMobile) {
4900
- expandMobileComposer();
4901
- return;
4902
- }
4903
- setIsComposerScrollCollapsed(false);
4904
- setIsComposerFocused(true);
4905
- scheduleComposerFocus();
4906
- }}
4907
- >
4908
- +{restingImagePreviewCounts.overflowCount}
4909
- </button>
4910
- ) : null}
4911
- </div>
4836
+ standaloneComposerImages.length > 0 ? (
4837
+ <ComposerRestingImagePreviews
4838
+ images={standaloneComposerImages}
4839
+ allImages={composerImages}
4840
+ resolvedTheme={resolvedTheme}
4841
+ onExpandImage={onExpandImage}
4842
+ onShowMore={showMoreRestingImages}
4843
+ />
4844
) : null;
4845
const { active: panelAnimationsActive, durationMs: panelAnimationDurationMs } =
4846
usePanelAnimationSettings();
@@ -6695,35 +6627,10 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
6627
pendingUserInputs.length === 0 &&
6628
editingQueuedAttachments !== null &&
6629
editingQueuedAttachments.length > 0 && (
6698
- <div className="mb-3 flex flex-wrap gap-2">
6699
- {editingQueuedAttachments.map(({ attachment, url }) => (
6700
- <div
6701
- key={attachment.id}
6702
- className="relative h-16 w-16 overflow-hidden rounded-lg border border-border/80 bg-background"
6703
- >
6704
- {attachment.type === "image" && url ? (
6705
- <img
6706
- src={url}
6707
- alt={attachment.name}
6708
- className="h-full w-full object-cover"
6709
- />
6710
- ) : (
6711
- <div className="flex h-full w-full items-center justify-center px-1 text-center text-3xs text-secondary-label">
6712
- {attachment.name}
6713
- </div>
6714
- )}
6715
- <Button
6716
- variant="media-close"
6717
- size="icon-xs"
6718
- className="absolute right-1 top-1"
6719
- onClick={() => onRemoveEditingQueuedAttachment(attachment.id)}
6720
- aria-label={`Remove ${attachment.name}`}
6721
- >
6722
- <XIcon />
6723
- </Button>
6724
- </div>
6725
- ))}
6726
- </div>
6630
+ <ComposerQueuedAttachmentRow
6631
+ attachments={editingQueuedAttachments}
6632
+ onRemove={onRemoveEditingQueuedAttachment}
6633
+ />
6634
)}
6635
6636
{composerAttachmentMediaRow}
apps/web/src/components/chat/ComposerAttachmentStrip.tsx
+121
@@ -1,4 +1,5 @@
1
import type {
2
+ ChatAttachment,
3
ChatFileAttachment,
4
EnvironmentId,
5
ScopedThreadRef,
@@ -24,6 +25,7 @@ import {
25
shouldAnimateSnapShotArrival,
26
} from "../../lib/snapShotAnimation";
27
import { cn } from "~/lib/utils";
28
+import { getRestingComposerImagePreviewCounts } from "../composerFooterLayout";
29
import { RefreshIcon } from "~/components/ui/refresh-icon";
30
import { AttachmentFilePreview } from "../files/AttachmentFilePreview";
31
import { AttachmentImage } from "../media/AttachmentImage";
@@ -533,3 +535,122 @@ export function ComposerFilePreviewDialog({
535
</Dialog>
536
);
537
}
538
+
539
+/** Thumbnails beside the single-line prompt while the composer rests. */
540
+export function ComposerRestingImagePreviews({
541
+ images,
542
+ allImages,
543
+ resolvedTheme,
544
+ onExpandImage,
545
+ onShowMore,
546
+}: {
547
+ readonly images: ReadonlyArray<ComposerImageAttachment>;
548
+ readonly allImages: ReadonlyArray<ComposerImageAttachment>;
549
+ readonly resolvedTheme: "light" | "dark";
550
+ readonly onExpandImage: (preview: ExpandedImagePreview) => void;
551
+ readonly onShowMore: () => void;
552
+}) {
553
+ const counts = getRestingComposerImagePreviewCounts(images.length);
554
+ const visibleImages = images.slice(0, counts.visibleCount);
555
+ return (
556
+ <div data-chat-composer-resting-images="true" className="flex shrink-0 items-center gap-1 ps-1">
557
+ {visibleImages.map((image) => (
558
+ <button
559
+ key={image.id}
560
+ type="button"
561
+ className="relative size-7 shrink-0 cursor-zoom-in overflow-hidden rounded-md border border-border/70 bg-muted/60"
562
+ aria-label={`Preview ${image.name}`}
563
+ onPointerDown={(event) => event.preventDefault()}
564
+ onClick={() => {
565
+ const preview = buildExpandedImagePreview(allImages, image.id);
566
+ if (preview) onExpandImage(preview);
567
+ }}
568
+ >
569
+ {image.previewUrl ? (
570
+ <ComposerImageThumbnail
571
+ file={image.file}
572
+ alt=""
573
+ className="size-full object-cover"
574
+ fallback={
575
+ isHeicImageFile({ name: image.name, type: image.mimeType }) ? (
576
+ <AttachmentImage
577
+ name={image.name}
578
+ mimeType={image.mimeType}
579
+ src={image.previewUrl}
580
+ alt=""
581
+ className="size-full object-cover"
582
+ />
583
+ ) : (
584
+ <PierreEntryIcon
585
+ pathValue={image.name}
586
+ kind="file"
587
+ theme={resolvedTheme}
588
+ className="m-auto size-3.5"
589
+ />
590
+ )
591
+ }
592
+ />
593
+ ) : (
594
+ <PierreEntryIcon
595
+ pathValue={image.name}
596
+ kind="file"
597
+ theme={resolvedTheme}
598
+ className="m-auto size-3.5"
599
+ />
600
+ )}
601
+ </button>
602
+ ))}
603
+ {counts.overflowCount > 0 ? (
604
+ <button
605
+ type="button"
606
+ className="flex size-7 shrink-0 cursor-pointer items-center justify-center rounded-md border border-border/70 bg-muted/60 font-medium text-secondary-label text-xs tabular-nums outline-none hover:bg-muted focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background"
607
+ aria-label={`Show ${String(counts.overflowCount)} more image attachments`}
608
+ onPointerDown={(event) => event.preventDefault()}
609
+ onClick={onShowMore}
610
+ >
611
+ +{counts.overflowCount}
612
+ </button>
613
+ ) : null}
614
+ </div>
615
+ );
616
+}
617
+
618
+/** Attachments of the queued message being edited; they are already uploaded. */
619
+export function ComposerQueuedAttachmentRow({
620
+ attachments,
621
+ onRemove,
622
+}: {
623
+ readonly attachments: ReadonlyArray<{
624
+ readonly attachment: ChatAttachment;
625
+ readonly url: string | null;
626
+ }>;
627
+ readonly onRemove: (attachmentId: string) => void;
628
+}) {
629
+ return (
630
+ <div className="mb-3 flex flex-wrap gap-2">
631
+ {attachments.map(({ attachment, url }) => (
632
+ <div
633
+ key={attachment.id}
634
+ className="relative h-16 w-16 overflow-hidden rounded-lg border border-border/80 bg-background"
635
+ >
636
+ {attachment.type === "image" && url ? (
637
+ <img src={url} alt={attachment.name} className="h-full w-full object-cover" />
638
+ ) : (
639
+ <div className="flex h-full w-full items-center justify-center px-1 text-center text-3xs text-secondary-label">
640
+ {attachment.name}
641
+ </div>
642
+ )}
643
+ <Button
644
+ variant="media-close"
645
+ size="icon-xs"
646
+ className="absolute right-1 top-1"
647
+ onClick={() => onRemove(attachment.id)}
648
+ aria-label={`Remove ${attachment.name}`}
649
+ >
650
+ <XIcon />
651
+ </Button>
652
+ </div>
653
+ ))}
654
+ </div>
655
+ );
656
+}