Skip to content

Commit 132f5ff

Browse files
committed
fix: prevent empty papers.zip download when no selections for Download Selected button
1 parent e1c6894 commit 132f5ff

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/components/CatalogueContent.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,14 @@ const CatalogueContent = () => {
212212
);
213213

214214
const handleDownloadSelected = useCallback(async () => {
215+
if (selectedPapers.length === 0) {
216+
toast.error("No papers selected for download.");
217+
return;
218+
}
215219
const zip = new JSZip();
216220
const uniquePapers = Array.from(
217221
new Set(selectedPapers.map((paper) => paper._id)),
218222
).map((id) => selectedPapers.find((paper) => paper._id === id)) as IPaper[];
219-
if (!uniquePapers) {
220-
toast.error("No papers selected for download.");
221-
}
222223
for (const paper of uniquePapers) {
223224
try {
224225
const response = await fetch(getSecureUrl(paper.file_url));
@@ -419,9 +420,9 @@ const CatalogueContent = () => {
419420
</div>
420421
</div>
421422

422-
423+
423424
{/* Select/Deselect/Download All Buttons */}
424-
425+
425426
<div className="mb-8 flex w-full items-center justify-end gap-4">
426427
<SidebarButton onClick={handleSelectAll}>
427428
Select All

0 commit comments

Comments
 (0)