From f2b8cb24572253869caea996fb492ec09570e598 Mon Sep 17 00:00:00 2001 From: Linrador <68631622+Linrador@users.noreply.github.com> Date: Mon, 8 Jun 2026 12:58:29 +0200 Subject: [PATCH] fixed delete overlay --- .../src/components/ui/FinishedDownloads.tsx | 88 +++++++++++++++++-- 1 file changed, 80 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/ui/FinishedDownloads.tsx b/frontend/src/components/ui/FinishedDownloads.tsx index c089cb6..66e669e 100644 --- a/frontend/src/components/ui/FinishedDownloads.tsx +++ b/frontend/src/components/ui/FinishedDownloads.tsx @@ -3670,7 +3670,33 @@ export default function FinishedDownloads({ const ok = window.confirm(`${selectedFiles.length} Downloads löschen?`) if (!ok) return + const selectedDeleteItems = selectedFiles + .map((file) => { + const cleanFile = String(file || '').trim() + if (!cleanFile) return null + + return { + file: cleanFile, + key: fileToKeyRef.current.get(cleanFile) || cleanFile, + } + }) + .filter(Boolean) as Array<{ file: string; key: string }> + + if (selectedDeleteItems.length === 0) return + + const selectedDeleteKeys = selectedDeleteItems.map((item) => item.key) + + // Sofort Overlay anzeigen, noch bevor der Bulk-Request läuft. + setDeletingKeys((prev) => { + const next = new Set(prev) + for (const key of selectedDeleteKeys) { + next.add(key) + } + return next + }) + setBulkBusy(true) + try { const res = await fetch('/api/record/delete-many', { method: 'POST', @@ -3686,20 +3712,57 @@ export default function FinishedDownloads({ const data = await res.json().catch(() => null) const results = Array.isArray(data?.results) ? data.results : [] - for (const item of results) { - if (!item?.ok) continue + const deletedKeys = new Set() + const failedKeys = new Set() - const file = String(item.file || '').trim() + for (const item of results) { + const file = String(item?.file || '').trim() if (!file) continue - const key = - fileToKeyRef.current.get(file) || - file + const key = fileToKeyRef.current.get(file) || file - animateRemove(key, file) + if (item?.ok) { + deletedKeys.add(key) + animateRemove(key, file) + } else { + failedKeys.add(key) + } } - const deletedCount = Number(data?.deleted ?? results.filter((x: any) => x?.ok).length ?? 0) + // Falls das Backend einzelne Dateien gar nicht zurückmeldet: + // nicht ewig als "Wird gelöscht" stehen lassen. + for (const item of selectedDeleteItems) { + if (!deletedKeys.has(item.key) && !failedKeys.has(item.key)) { + failedKeys.add(item.key) + } + } + + if (failedKeys.size > 0) { + setDeletingKeys((prev) => { + const next = new Set(prev) + for (const key of failedKeys) { + next.delete(key) + } + return next + }) + } + + // Erfolgreiche Keys nach der Remove-Animation aus dem Busy-State räumen. + if (deletedKeys.size > 0) { + window.setTimeout(() => { + setDeletingKeys((prev) => { + const next = new Set(prev) + for (const key of deletedKeys) { + next.delete(key) + } + return next + }) + }, 450) + } + + const deletedCount = Number( + data?.deleted ?? results.filter((x: any) => x?.ok).length ?? 0 + ) clearSelection() emitCountHint(-deletedCount) @@ -3708,6 +3771,15 @@ export default function FinishedDownloads({ notify.success?.('Löschen erfolgreich', `${deletedCount} Downloads gelöscht.`) } } catch (e: any) { + // Bei komplettem Fehler alle zuvor markierten Overlays wieder entfernen. + setDeletingKeys((prev) => { + const next = new Set(prev) + for (const key of selectedDeleteKeys) { + next.delete(key) + } + return next + }) + notify.error('Bulk-Löschen fehlgeschlagen', String(e?.message || e)) } finally { setBulkBusy(false)