feat: bulk tag editing, bulk export, and move recipes between collections

Extends the existing bulk-select infra: recipes list gets tag add/remove
and multi-recipe Markdown export; collection pages get a select mode to
move recipes to another collection or remove them from the current one.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Arnaud
2026-07-13 11:57:07 +02:00
parent 4960dfc7c6
commit 70eb565eec
14 changed files with 533 additions and 18 deletions
+58 -1
View File
@@ -3,8 +3,9 @@
import { useState, useCallback, useEffect } from "react";
import Image from "next/image";
import { useTranslations } from "next-intl";
import { Trash2, Globe, Lock, Link2, X, Check, ListChecks, LayoutGrid, List, Rows3, FolderPlus, ChefHat, ExternalLink } from "lucide-react";
import { Trash2, Globe, Lock, Link2, X, Check, ListChecks, LayoutGrid, List, Rows3, FolderPlus, ChefHat, ExternalLink, Tag, Download } from "lucide-react";
import { AddToCollectionDialog } from "@/components/recipe/add-to-collection-dialog";
import { BulkTagsDialog } from "@/components/recipe/bulk-tags-dialog";
import { Button, buttonVariants } from "@/components/ui/button";
import {
DropdownMenu,
@@ -407,6 +408,8 @@ export function RecipesGrid({ recipes: initialRecipes }: { recipes: Recipe[] })
const [viewMode, setViewMode] = useState<ViewMode>("grid");
const [addToCollectionOpen, setAddToCollectionOpen] = useState(false);
const [deleteConfirmOpen, setDeleteConfirmOpen] = useState(false);
const [bulkTagsOpen, setBulkTagsOpen] = useState(false);
const [exporting, setExporting] = useState(false);
useEffect(() => {
const stored = localStorage.getItem(VIEW_STORAGE_KEY) as ViewMode | null;
@@ -473,9 +476,47 @@ export function RecipesGrid({ recipes: initialRecipes }: { recipes: Recipe[] })
}
}
function applyBulkTags(addTags: string[], removeTags: string[]) {
setRecipes((prev) =>
prev.map((r) =>
selected.has(r.id)
? { ...r, tags: [...new Set([...r.tags.filter((tag) => !removeTags.includes(tag)), ...addTags])] }
: r
)
);
exitSelect();
}
async function bulkExport() {
setExporting(true);
try {
const res = await fetch("/api/v1/recipes/bulk/export", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ ids: [...selected] }),
});
if (!res.ok) throw new Error();
const { markdown } = (await res.json()) as { markdown: string };
const blob = new Blob([markdown], { type: "text/markdown;charset=utf-8" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "recipes.md";
document.body.appendChild(a);
a.click();
a.remove();
URL.revokeObjectURL(url);
} catch {
toast.error(t("bulkExportFailed"));
} finally {
setExporting(false);
}
}
if (recipes.length === 0) return null;
const allSelected = selected.size === recipes.length;
const availableTagsForRemoval = [...new Set(recipes.filter((r) => selected.has(r.id)).flatMap((r) => r.tags))];
return (
<div className="space-y-4">
@@ -555,6 +596,14 @@ export function RecipesGrid({ recipes: initialRecipes }: { recipes: Recipe[] })
<FolderPlus className="h-4 w-4" />
<span className="hidden sm:inline">{t("addToCollection")}</span>
</Button>
<Button variant="ghost" size="sm" onClick={() => setBulkTagsOpen(true)} disabled={busy} className="gap-1.5 shrink-0" aria-label={t("bulkTagsButton")}>
<Tag className="h-4 w-4" />
<span className="hidden sm:inline">{t("bulkTagsButton")}</span>
</Button>
<Button variant="ghost" size="sm" onClick={() => { void bulkExport(); }} disabled={exporting || busy} className="gap-1.5 shrink-0" aria-label={t("bulkExportButton")}>
<Download className="h-4 w-4" />
<span className="hidden sm:inline">{t("bulkExportButton")}</span>
</Button>
<Button variant="destructive" size="sm" onClick={() => setDeleteConfirmOpen(true)} disabled={busy} className="gap-1.5 shrink-0" aria-label={tCommon("delete")}>
<Trash2 className="h-4 w-4" />
<span className="hidden sm:inline">{tCommon("delete")}</span>
@@ -570,6 +619,14 @@ export function RecipesGrid({ recipes: initialRecipes }: { recipes: Recipe[] })
onDone={exitSelect}
/>
<BulkTagsDialog
open={bulkTagsOpen}
onOpenChange={setBulkTagsOpen}
recipeIds={[...selected]}
availableTags={availableTagsForRemoval}
onDone={applyBulkTags}
/>
<AlertDialog open={deleteConfirmOpen} onOpenChange={setDeleteConfirmOpen}>
<AlertDialogContent>
<AlertDialogHeader>