From 55c36de9a4c047f24d78da1289dadcfeb3a15532 Mon Sep 17 00:00:00 2001 From: Ramesh Choudhary Date: Wed, 25 Nov 2026 16:44:41 +0530 Subject: [PATCH 1/3] feat(attachments): stop a download from the attachment chip The downloads panel already shows each transfer's progress, so the chip's own progress line repeated it. While an attachment downloads or is scanned, the chip now shows a spinner with a stop button instead, and the panel keeps the full progress. Errors and the not-scanned notice still show under the chip. --- CHANGELOG.md | 6 ++ .../attachment-viewer/AttachmentChips.tsx | 10 ++- .../AttachmentDownloadStatus.tsx | 83 +++++++++++++++++-- .../attachment-viewer/AttachmentPills.tsx | 14 +++- apps/desktop/src/styles/chat-view-theme.css | 19 +++++ .../AttachmentDownloadStatus.test.tsx | 66 ++++++++++++++- .../AttachmentTransferProvider.test.tsx | 24 ++++++ 7 files changed, 208 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 591e5617..deda08ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed +- **Stop an attachment download from the attachment itself.** While an + attachment downloads or is scanned, its chip in the message shows a spinner + with a stop button in place of a progress line under it. The downloads panel + still shows the full progress. + ## [1.5.0] - 2026-11-25 ### Added diff --git a/apps/desktop/src/components/attachment-viewer/AttachmentChips.tsx b/apps/desktop/src/components/attachment-viewer/AttachmentChips.tsx index dfc9ad5d..b9d43817 100644 --- a/apps/desktop/src/components/attachment-viewer/AttachmentChips.tsx +++ b/apps/desktop/src/components/attachment-viewer/AttachmentChips.tsx @@ -1,10 +1,10 @@ -import { Download, Loader2, Paperclip } from 'lucide-react'; +import { Download, Paperclip } from 'lucide-react'; import { useState } from 'react'; import { getFileIcon, getFileType } from '../email-detail/utils'; import { Tooltip } from '../Tooltip'; -import { AttachmentDownloadStatus } from './AttachmentDownloadStatus'; +import { AttachmentDownloadStatus, AttachmentStopButton } from './AttachmentDownloadStatus'; import { AttachmentViewer, type ViewerAttachment } from './AttachmentViewer'; import { useAttachmentActions } from './useAttachmentActions'; @@ -93,6 +93,8 @@ export function AttachmentChips({
{attachments.map((attachment, index) => { const busy = isBusy(emailId, attachment.name, accountId); + const status = getStatus(emailId, attachment.name, accountId); + const cancel = () => { void cancelDownload(emailId, attachment.name, accountId); }; return (
{busy ? ( - + ) : ( getFileIcon(attachment.name) )} @@ -132,7 +134,7 @@ export function AttachmentChips({
{!busy && getFileType(attachment.name)}
- { void cancelDownload(emailId, attachment.name, accountId); }} /> +
); diff --git a/apps/desktop/src/components/attachment-viewer/AttachmentDownloadStatus.tsx b/apps/desktop/src/components/attachment-viewer/AttachmentDownloadStatus.tsx index c9989be5..be94e5a1 100644 --- a/apps/desktop/src/components/attachment-viewer/AttachmentDownloadStatus.tsx +++ b/apps/desktop/src/components/attachment-viewer/AttachmentDownloadStatus.tsx @@ -1,7 +1,9 @@ -import { X } from 'lucide-react'; +import { Loader2, Square, X } from 'lucide-react'; +import { useContext } from 'react'; import { Tooltip } from '../Tooltip'; +import { AttachmentActionsContext } from './attachment-actions-context'; import type { AttachmentDownloadState } from './useAttachmentActions'; /** An accepted missing-setup warning is never represented as a clean scan. */ @@ -9,18 +11,85 @@ export function UnscannedAttachmentNotice() { return

Not scanned for viruses.

; } -/** The same trusted progress, cancellation and blocked-attachment message everywhere. */ +/** + * Whether the app-wide Attachments panel (AttachmentTransferProvider) is + * showing this attachment's progress. It is mounted around the whole app; an + * isolated embed without it has no other place to show progress. + */ +export function useAttachmentTransferPanel(): boolean { + return useContext(AttachmentActionsContext) !== undefined; +} + +type Action = 'preview' | 'open' | 'download'; + +function actionOf(status: AttachmentDownloadState): Action { + return status.operation === 'preview' ? 'preview' : status.operation === 'open' ? 'open' : 'download'; +} + +/** + * The busy spinner of an attachment chip, as the control that stops it. + * + * A stop square sits inside the spinning ring, so the way to stop is where the + * eye already is, rather than in a status line under the chip that repeats what + * the Attachments panel shows. A transfer that cannot be cancelled (a system + * open) keeps a plain spinner: a stop button that does nothing is worse than + * none. + */ +export function AttachmentStopButton({ + status, + filename, + onCancel, + className = '', + iconClassName = 'h-3.5 w-3.5', +}: { + status?: AttachmentDownloadState; + filename: string; + onCancel: () => void; + className?: string; + iconClassName?: string; +}) { + if (!status?.phase) return null; + if (!status.canCancel) return