feat: collections visibility enum (matches recipes) + QR on collection PDF (v0.54.0)

Replaces collections.isPublic (boolean) with collections.visibility
(private/unlisted/public/followers — same enum recipes use). Two-step
migration (0050 adds+backfills, 0051 drops isPublic) since drizzle-kit's
add+drop-in-one-diff rename heuristic needs an interactive prompt we
can't satisfy here.

New collectionVisibleToViewer(viewerId) in lib/visibility.ts mirrors the
existing recipe helper (author always sees own; public/unlisted visible
to anyone; followers-only via the same user_follows EXISTS pattern) —
used by the collection detail page, its print view, fork, and favorite,
replacing their old `or(isPublic, own)` checks.

Create/edit collection dialogs get the same 4-option visibility select
as the recipe form instead of a public/private checkbox.

Collection PDF export now generates a QR code (qrcode, same as the
recipe PDF) linking to /collections/{id}, shown only when visibility is
public/unlisted — same "would an anonymous scanner actually resolve
this" rule as the recipe QR.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Arnaud
2026-07-19 19:26:34 +02:00
parent b1f745da66
commit 9da57dd1d0
25 changed files with 11217 additions and 56 deletions
@@ -11,15 +11,18 @@ import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { Label } from "@/components/ui/label";
type Visibility = "private" | "unlisted" | "public" | "followers";
export function NewCollectionButton() {
const t = useTranslations("collections");
const tSocial = useTranslations("social");
const tCommon = useTranslations("common");
const tRecipe = useTranslations("recipe");
const router = useRouter();
const [open, setOpen] = useState(false);
const [name, setName] = useState("");
const [description, setDescription] = useState("");
const [isPublic, setIsPublic] = useState(false);
const [visibility, setVisibility] = useState<Visibility>("private");
const [saving, setSaving] = useState(false);
async function create() {
@@ -29,13 +32,13 @@ export function NewCollectionButton() {
const res = await fetch("/api/v1/collections", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: name.trim(), description: description.trim() || undefined, isPublic }),
body: JSON.stringify({ name: name.trim(), description: description.trim() || undefined, visibility }),
});
if (!res.ok) { toast.error(t("createFailed")); return; }
const { id } = await res.json() as { id: string };
toast.success(tSocial("collectionCreated"));
setOpen(false);
setName(""); setDescription(""); setIsPublic(false);
setName(""); setDescription(""); setVisibility("private");
router.push(`/collections/${id}`);
router.refresh();
} finally {
@@ -60,10 +63,20 @@ export function NewCollectionButton() {
<Label htmlFor="col-desc">{t("descriptionLabel")}</Label>
<Textarea id="col-desc" value={description} onChange={(e) => setDescription(e.target.value)} rows={2} placeholder={t("descriptionPlaceholder")} />
</div>
<label className="flex items-center gap-2 text-sm cursor-pointer">
<input type="checkbox" checked={isPublic} onChange={(e) => setIsPublic(e.target.checked)} className="rounded" />
{t("makePublic")}
</label>
<div className="space-y-2">
<Label htmlFor="col-visibility">{tRecipe("visibilityMenuLabel")}</Label>
<select
id="col-visibility"
value={visibility}
onChange={(e) => setVisibility(e.target.value as Visibility)}
className="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs"
>
<option value="private">{tRecipe("visibility.private")}</option>
<option value="followers">{tRecipe("visibility.followers")}</option>
<option value="unlisted">{tRecipe("visibility.unlisted")}</option>
<option value="public">{tRecipe("visibility.public")}</option>
</select>
</div>
<div className="flex gap-2 justify-end">
<Button variant="outline" onClick={() => setOpen(false)}>{tCommon("cancel")}</Button>
<Button onClick={create} disabled={!name.trim() || saving}>{saving ? t("creating") : t("create")}</Button>