@@ -34,6 +34,7 @@ import { Dialog, DialogPopup, DialogTitle } from "../ui/dialog";
3434import { Tooltip , TooltipPopup , TooltipTrigger } from "../ui/tooltip" ;
3535import { ComposerImageThumbnail } from "./ComposerImageThumbnail" ;
3636import { composerFloatingLayerProps } from "./composerEventScope" ;
37+ import type { PreparingComposerImage } from "./preparingComposerImages" ;
3738import {
3839 attachVideoThumbnail ,
3940 buildExpandedImagePreview ,
@@ -109,6 +110,7 @@ function SnapShotAttachmentFrame({
109110export function ComposerAttachmentMediaRow ( {
110111 images,
111112 expandedImages,
113+ preparingImages,
112114 videos,
113115 pendingSnapShotAnimations,
114116 pendingSnapShotIds,
@@ -127,6 +129,7 @@ export function ComposerAttachmentMediaRow({
127129} : {
128130 readonly images : ReadonlyArray < ComposerImageAttachment > ;
129131 readonly expandedImages : ReadonlyArray < ComposerImageAttachment > ;
132+ readonly preparingImages : ReadonlyArray < PreparingComposerImage > ;
130133 readonly videos : ReadonlyArray < ComposerFileAttachment > ;
131134 readonly pendingSnapShotAnimations : ReadonlyArray < PendingSnapShotAnimation > ;
132135 readonly pendingSnapShotIds : ReadonlyArray < string > ;
@@ -156,14 +159,20 @@ export function ComposerAttachmentMediaRow({
156159 : "flex-wrap" ,
157160 ) }
158161 >
159- { expandedImages
160- . map ( ( image ) => {
161- const upload = supportsAttachmentUploads ? uploadsByImageId [ image . id ] : undefined ;
162+ { /* A preparing image renders through the same tile, keyed by the id its compressed image
163+ takes, so the thumbnail element survives the swap. */ }
164+ { [
165+ ...expandedImages . map ( ( image ) => ( { image, ready : image } ) ) ,
166+ ...preparingImages . map ( ( image ) => ( { image, ready : null } ) ) ,
167+ ]
168+ . map ( ( { image, ready } ) => {
169+ const upload =
170+ ready && supportsAttachmentUploads ? uploadsByImageId [ image . id ] : undefined ;
171+ const source = ready ?. source ;
162172 const snapShotAnimationPending =
163- image . source ?. kind === "snap-shot" && pendingSnapShotIdSet . has ( image . id ) ;
173+ source ?. kind === "snap-shot" && pendingSnapShotIdSet . has ( image . id ) ;
164174 const snapShotArrival =
165- image . source ?. kind === "snap-shot" &&
166- shouldAnimateSnapShotArrival ( image . source . capturedAt ) ;
175+ source ?. kind === "snap-shot" && shouldAnimateSnapShotArrival ( source . capturedAt ) ;
167176 return (
168177 < SnapShotAttachmentFrame
169178 key = { image . id }
@@ -173,20 +182,21 @@ export function ComposerAttachmentMediaRow({
173182 arrival = { snapShotArrival }
174183 animateArrival = { snapShotAnimations && ! snapShotAnimationPending && snapShotArrival }
175184 animationId = { snapShotAnimationPending ? image . id : undefined }
176- animationSource = { snapShotAnimationPending ? image . source : undefined }
185+ animationSource = { snapShotAnimationPending ? source : undefined }
177186 className = { cn (
178187 "group/attachment shrink-0 snap-start bg-background" ,
179- image . source ?. kind === "snap-shot"
188+ source ?. kind === "snap-shot"
180189 ? SNAP_SHOT_ATTACHMENT_FRAME_CLASS
181190 : "relative h-16 w-16 overflow-hidden rounded-lg border border-border/80" ,
182191 snapShotAnimationPending && "invisible" ,
183192 ) }
184193 >
185- { image . previewUrl ? (
194+ { ! ready || ready . previewUrl ? (
186195 < button
187196 type = "button"
188- className = "h-full w-full cursor-zoom-in"
197+ className = { cn ( "h-full w-full" , ready && " cursor-zoom-in") }
189198 aria-label = { `Preview ${ image . name } ` }
199+ disabled = { ! ready }
190200 onClick = { ( ) => {
191201 const preview = buildExpandedImagePreview ( images , image . id ) ;
192202 if ( ! preview ) return ;
@@ -198,11 +208,11 @@ export function ComposerAttachmentMediaRow({
198208 alt = { image . name }
199209 className = "h-full w-full object-cover"
200210 fallback = {
201- isHeicImageFile ( { name : image . name , type : image . mimeType } ) ? (
211+ ready && isHeicImageFile ( { name : ready . name , type : ready . mimeType } ) ? (
202212 < AttachmentImage
203- name = { image . name }
204- mimeType = { image . mimeType }
205- src = { image . previewUrl }
213+ name = { ready . name }
214+ mimeType = { ready . mimeType }
215+ src = { ready . previewUrl }
206216 alt = { image . name }
207217 className = "h-full w-full object-cover"
208218 />
@@ -219,9 +229,9 @@ export function ComposerAttachmentMediaRow({
219229 { image . name }
220230 </ div >
221231 ) }
222- { image . source ?. kind === "snap-shot" ? (
232+ { source ?. kind === "snap-shot" ? (
223233 < SnapShotAttachmentDetails
224- source = { image . source }
234+ source = { source }
225235 className = { cn (
226236 upload ?. status === "uploading" && "bottom-4" ,
227237 upload ?. status === "failed" && "bottom-8" ,
@@ -246,12 +256,14 @@ export function ComposerAttachmentMediaRow({
246256 </ TooltipPopup >
247257 </ Tooltip >
248258 ) }
249- { upload ?. status === "uploading" && (
259+ { ( ready ? upload ?. status === "uploading" : supportsAttachmentUploads ) && (
250260 < span className = "pointer-events-none absolute inset-x-0 bottom-0 bg-background/85 px-1 text-center text-3xs text-foreground" >
251- { formatAttachmentUploadProgress ( upload . progress ) }
261+ { formatAttachmentUploadProgress (
262+ upload ?. status === "uploading" ? upload . progress : 0 ,
263+ ) }
252264 </ span >
253265 ) }
254- { upload ?. status === "failed" && (
266+ { ready && upload ?. status === "failed" && (
255267 < Tooltip >
256268 < TooltipTrigger
257269 render = {
@@ -262,7 +274,7 @@ export function ComposerAttachmentMediaRow({
262274 onClick = { ( ) =>
263275 retryAttachmentUpload ( {
264276 environmentId,
265- image,
277+ image : ready ,
266278 draftTarget : attachmentDraftTarget ,
267279 } )
268280 }
@@ -279,7 +291,7 @@ export function ComposerAttachmentMediaRow({
279291 < span
280292 className = { cn (
281293 "absolute right-1 top-1 flex" ,
282- image . source ?. kind === "snap-shot" &&
294+ source ?. kind === "snap-shot" &&
283295 "opacity-0 transition-opacity pointer-coarse:opacity-100 group-hover/attachment:opacity-100 group-focus-within/attachment:opacity-100" ,
284296 ) }
285297 >
0 commit comments