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:
@@ -4,7 +4,8 @@ import { headers } from "next/headers";
|
||||
import Link from "next/link";
|
||||
import { Printer, UtensilsCrossed, StickyNote } from "lucide-react";
|
||||
import { auth } from "@/lib/auth/server";
|
||||
import { db, collections, eq, and, or } from "@epicure/db";
|
||||
import { db, collections, eq, and } from "@epicure/db";
|
||||
import { collectionVisibleToViewer } from "@/lib/visibility";
|
||||
import { RecipeGridCard } from "@/components/recipe/recipe-grid-card";
|
||||
import { CollectionRecipesGrid } from "@/components/collections/collection-recipes-grid";
|
||||
import { ForkCollectionButton } from "@/components/collections/fork-collection-button";
|
||||
@@ -32,10 +33,7 @@ export default async function CollectionPage({ params }: Params) {
|
||||
const m = getMessages((session.user as { locale?: string }).locale);
|
||||
|
||||
const col = await db.query.collections.findFirst({
|
||||
where: and(
|
||||
eq(collections.id, id),
|
||||
or(eq(collections.userId, session.user.id), eq(collections.isPublic, true))
|
||||
),
|
||||
where: and(eq(collections.id, id), collectionVisibleToViewer(session.user.id)),
|
||||
with: {
|
||||
recipes: {
|
||||
orderBy: (t, { asc }) => asc(t.position),
|
||||
@@ -63,7 +61,7 @@ export default async function CollectionPage({ params }: Params) {
|
||||
</div>
|
||||
)}
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
{recipeList.length} recipe{recipeList.length !== 1 ? "s" : ""} · {col.isPublic ? "Public" : "Private"}
|
||||
{recipeList.length} recipe{recipeList.length !== 1 ? "s" : ""} · {m.recipe.visibility[col.visibility]}
|
||||
</p>
|
||||
{isOwner && col.notes && (
|
||||
<div className="mt-2 flex items-start gap-2 rounded-lg border bg-muted/30 px-3 py-2 text-sm text-muted-foreground max-w-2xl">
|
||||
@@ -103,11 +101,11 @@ export default async function CollectionPage({ params }: Params) {
|
||||
initialDescription={col.description}
|
||||
initialNotes={col.notes}
|
||||
initialTags={col.tags}
|
||||
initialIsPublic={col.isPublic}
|
||||
initialVisibility={col.visibility}
|
||||
/>
|
||||
)}
|
||||
{isOwner && <DeleteCollectionDialog collectionId={id} />}
|
||||
{!isOwner && col.isPublic && (
|
||||
{!isOwner && (col.visibility === "public" || col.visibility === "unlisted") && (
|
||||
<ForkCollectionButton collectionId={id} />
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -49,7 +49,7 @@ export default async function ExploreCollectionsPage() {
|
||||
collectionFavorites,
|
||||
and(eq(collectionFavorites.collectionId, collections.id), gte(collectionFavorites.createdAt, sevenDaysAgo))
|
||||
)
|
||||
.where(eq(collections.isPublic, true))
|
||||
.where(eq(collections.visibility, "public"))
|
||||
.groupBy(collections.id, users.id)
|
||||
.orderBy(desc(sql`count(${collectionFavorites.collectionId})`))
|
||||
.limit(12);
|
||||
@@ -63,7 +63,7 @@ export default async function ExploreCollectionsPage() {
|
||||
})
|
||||
.from(collections)
|
||||
.innerJoin(users, eq(collections.userId, users.id))
|
||||
.where(eq(collections.isPublic, true))
|
||||
.where(eq(collections.visibility, "public"))
|
||||
.orderBy(desc(collections.createdAt))
|
||||
.limit(12);
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ export default async function CollectionsPage({
|
||||
name: col.name,
|
||||
description: col.description,
|
||||
tags: col.tags,
|
||||
isPublic: col.isPublic,
|
||||
visibility: col.visibility,
|
||||
recipeCount: countByCollection.get(col.id) ?? 0,
|
||||
thumbnails: col.recipes.flatMap((r) => {
|
||||
if (!r.recipe) return [];
|
||||
|
||||
Reference in New Issue
Block a user