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:
@@ -12,23 +12,26 @@ import { Textarea } from "@/components/ui/textarea";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
|
||||
type Visibility = "private" | "unlisted" | "public" | "followers";
|
||||
|
||||
export function EditCollectionDialog({
|
||||
collectionId,
|
||||
initialName,
|
||||
initialDescription,
|
||||
initialNotes,
|
||||
initialTags,
|
||||
initialIsPublic,
|
||||
initialVisibility,
|
||||
}: {
|
||||
collectionId: string;
|
||||
initialName: string;
|
||||
initialDescription: string | null;
|
||||
initialNotes: string | null;
|
||||
initialTags: string[];
|
||||
initialIsPublic: boolean;
|
||||
initialVisibility: Visibility;
|
||||
}) {
|
||||
const t = useTranslations("collections");
|
||||
const tRecipeForm = useTranslations("recipeForm");
|
||||
const tRecipe = useTranslations("recipe");
|
||||
const tCommon = useTranslations("common");
|
||||
const router = useRouter();
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -37,7 +40,7 @@ export function EditCollectionDialog({
|
||||
const [notes, setNotes] = useState(initialNotes ?? "");
|
||||
const [tags, setTags] = useState<string[]>(initialTags);
|
||||
const [tagInput, setTagInput] = useState("");
|
||||
const [isPublic, setIsPublic] = useState(initialIsPublic);
|
||||
const [visibility, setVisibility] = useState<Visibility>(initialVisibility);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const tagInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
@@ -73,7 +76,7 @@ export function EditCollectionDialog({
|
||||
description: description.trim() || null,
|
||||
notes: notes.trim() || null,
|
||||
tags,
|
||||
isPublic,
|
||||
visibility,
|
||||
}),
|
||||
});
|
||||
if (!res.ok) throw new Error();
|
||||
@@ -151,10 +154,20 @@ export function EditCollectionDialog({
|
||||
</div>
|
||||
</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="edit-col-visibility">{tRecipe("visibilityMenuLabel")}</Label>
|
||||
<select
|
||||
id="edit-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>
|
||||
|
||||
<DialogFooter>
|
||||
|
||||
Reference in New Issue
Block a user