Show attachment download progress

This commit is contained in:
TerryM
2026-05-27 12:23:06 +08:00
parent 9453777dba
commit 54841a4ed9
6 changed files with 125 additions and 59 deletions

View File

@@ -8,10 +8,9 @@ import {
type PropsWithChildren,
} from "react";
import { createPortal } from "react-dom";
import { ChevronLeft, ChevronRight, Download, X } from "lucide-react";
import { ChevronLeft, ChevronRight, X } from "lucide-react";
import type { Attachment } from "../../../types/post";
import { autolink } from "../utils/autolink";
import { downloadAttachment, downloadFile } from "../utils/downloadFile";
type LightboxState = {
images: Attachment[];
@@ -66,7 +65,6 @@ export function ImageLightboxProvider({ children }: PropsWithChildren) {
images={state.images}
startIndex={state.index}
caption={state.caption}
postId={state.postId}
onClose={closeLightbox}
/>
) : null}
@@ -78,13 +76,11 @@ function LightboxView({
images,
startIndex,
caption: captionText,
postId,
onClose,
}: {
images: Attachment[];
startIndex: number;
caption?: string;
postId?: string;
onClose: () => void;
}) {
const [index, setIndex] = useState(startIndex);
@@ -137,24 +133,6 @@ function LightboxView({
<X className="h-5 w-5" />
</button>
<button
type="button"
onClick={(e) => {
e.stopPropagation();
if (postId) {
void downloadAttachment(postId, current.id, current.filename).catch(
() => {},
);
} else {
void downloadFile(current.url, current.filename).catch(() => {});
}
}}
className="absolute right-16 top-4 z-10 flex h-10 w-10 items-center justify-center rounded-full bg-white/10 text-white transition hover:bg-white/20"
aria-label="Download"
>
<Download className="h-5 w-5" />
</button>
{images.length > 1 ? (
<>
<button