diff --git a/apps/mobile/src/components/ComposerAttachmentStrip.tsx b/apps/mobile/src/components/ComposerAttachmentStrip.tsx index 8e5a954501d8e..767a689568131 100644 --- a/apps/mobile/src/components/ComposerAttachmentStrip.tsx +++ b/apps/mobile/src/components/ComposerAttachmentStrip.tsx @@ -215,6 +215,8 @@ function ComposerFileAttachment( const canPreview = isPdfFile(attachment) && props.onPressPreview !== undefined; const sourceIdentifier = `draft-file:${attachment.id}`; const onPressDocument = props.onPressDocument; + const upload = useComposerAttachmentUploadState(props.environmentId, attachment.id); + const showsUploadBadge = upload !== undefined && upload.status !== "ready"; return ( <> @@ -235,7 +237,7 @@ function ComposerFileAttachment( className={ props.compact ? "items-center justify-center bg-subtle" - : "items-center justify-center gap-1 bg-subtle px-2" + : `items-center justify-center gap-1 bg-subtle px-2${showsUploadBadge ? " pb-4" : ""}` } style={style} > diff --git a/apps/mobile/src/features/threads/ThreadComposer.tsx b/apps/mobile/src/features/threads/ThreadComposer.tsx index 76bb79d608682..19ca8397aa64e 100644 --- a/apps/mobile/src/features/threads/ThreadComposer.tsx +++ b/apps/mobile/src/features/threads/ThreadComposer.tsx @@ -84,6 +84,7 @@ import { composerStripAttachments, type DraftComposerFileAttachment, } from "../../lib/composerImages"; +import { composerAttachmentUploadKey } from "../../lib/composerAttachmentUploadQueue"; import { buildModelOptions, isModelSelectionUnavailable, @@ -303,7 +304,6 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps draftMessage.trim().length > 0 || draftAttachments.length > 0 || (queuedEdit?.existingAttachments.length ?? 0) > 0; - const stripAttachments = composerStripAttachments(draftAttachments); const showStopAction = !hasContent && props.canStopThread && queuedEdit === null; const onResumeQueue = props.onResumeQueue; const [resumingQueue, setResumingQueue] = useState(false); @@ -321,6 +321,12 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps AuthOrchestrationOperateScope, ); const uploadStates = useAtomValue(composerAttachmentUploadsAtom); + const stripAttachments = composerStripAttachments( + draftAttachments, + (attachment) => + uploadStates[composerAttachmentUploadKey(props.environmentId, attachment.id)]?.status === + "failed", + ); const attachmentsUploading = props.connectionState === "connected" && composerAttachmentsStillUploading({ diff --git a/apps/mobile/src/lib/composerImages.test.ts b/apps/mobile/src/lib/composerImages.test.ts index b5b10ac02c7bb..367c6cf3896eb 100644 --- a/apps/mobile/src/lib/composerImages.test.ts +++ b/apps/mobile/src/lib/composerImages.test.ts @@ -332,10 +332,16 @@ describe("composerStripAttachments", () => { it("keeps media beside a document rather than dropping the whole strip", async () => { const { composerStripAttachments } = await import("./composerImages"); - expect(composerStripAttachments([doc, image, video] as never).map((a) => a.id)).toEqual([ - "img-1", - "vid-1", - ]); + expect( + composerStripAttachments([doc, image, video] as never, () => false).map((a) => a.id), + ).toEqual(["img-1", "vid-1"]); + }); + + it("shows a document whose upload failed, so it can be retried", async () => { + const { composerStripAttachments } = await import("./composerImages"); + expect( + composerStripAttachments([doc, image] as never, (a) => a.id === "doc-1").map((a) => a.id), + ).toEqual(["doc-1", "img-1"]); }); it("keeps oversized document-picked images visible while sending them as files", async () => { @@ -350,7 +356,7 @@ describe("composerStripAttachments", () => { sizeBytes: PROVIDER_SEND_TURN_MAX_IMAGE_BYTES + 1, }; - expect(composerStripAttachments([oversizedImage])).toEqual([oversizedImage]); + expect(composerStripAttachments([oversizedImage], () => false)).toEqual([oversizedImage]); expect(isComposerImageAttachment(oversizedImage)).toBe(false); }); }); diff --git a/apps/mobile/src/lib/composerImages.ts b/apps/mobile/src/lib/composerImages.ts index 34abd9f9456ec..3ca64eef41fe8 100644 --- a/apps/mobile/src/lib/composerImages.ts +++ b/apps/mobile/src/lib/composerImages.ts @@ -80,15 +80,20 @@ export async function createPastedTextComposerAttachment(input: { export type DraftComposerAttachment = DraftComposerImageAttachment | DraftComposerFileAttachment; -/** Non-media attachments require chip references; missing references mean lost draft files. */ +/** + * Non-media attachments require chip references; missing references mean lost draft files. + * A chip cannot retry an upload, so a document whose upload failed joins the strip. + */ export function composerStripAttachments( attachments: ReadonlyArray, + uploadFailed: (attachment: DraftComposerAttachment) => boolean, ): ReadonlyArray { return attachments.filter( (attachment) => attachment.type === "image" || imageMimeType(attachment) !== null || - videoMimeType(attachment) !== null, + videoMimeType(attachment) !== null || + uploadFailed(attachment), ); }