import { LoaderCircle } from "lucide-react"; import { DownloadCloudIcon } from "../icons/DownloadCloudIcon"; import { useState, type MouseEvent } from "react"; import { useI18n } from "../../i18n"; import type { Attachment } from "../../types/post"; import { downloadAttachment } from "./utils/downloadFile"; import { formatBytes } from "./utils/formatBytes"; type AttachmentDownloadPillProps = { postId: string; attachment: Attachment; leadingLabel?: string; className?: string; }; export function AttachmentDownloadPill({ postId, attachment, leadingLabel, className = "absolute left-2 top-2", }: AttachmentDownloadPillProps) { const { t } = useI18n(); const [isDownloading, setIsDownloading] = useState(false); const handleDownload = (e: MouseEvent) => { e.stopPropagation(); if (isDownloading) return; setIsDownloading(true); void downloadAttachment(postId, attachment.id, attachment.filename) .finally(() => setIsDownloading(false)) .catch(() => {}); }; return ( ); }