feat: cooking history/gallery, unit conversion, nutrition diary, pantry scan, digest cron, nutrition-targeted meal plans
Six M-sized items from HANDOFF.md's new-features backlog: - Profile tabs: cooking-history stats (total cooked, last-cooked, streak) and a "cooked it" photo gallery, both owner-only - Display-time unit conversion (metric<->imperial) for recipe ingredients, respecting each user's unitPref; original value always shown alongside the conversion - Nutrition daily diary: per-day macro totals computed from cooking history x recipe nutritionData, compared against user goals - Pantry scan: real barcode lookup (zxing + Open Food Facts, no API key) with an AI-vision fallback for unbarcoded items, always confirm-before- insert, both paths tier/rate-limited like other AI features - Weekly digest email: new followers/comments/ratings + trending recipes, sent via a new `cron` Docker stage (alpine+crond+curl) and `digest-cron` compose service hitting a bearer-token-protected internal route - Meal-plan generation can now target a user's nutrition goals as a prompt-level nudge (recipes are AI-invented, not DB-sourced, so this can't be a hard macro constraint) Caught a real deploy-breaking issue while adding the cron stage: appending it after `runner` silently changed the Dockerfile's default build target, and `web`'s compose config didn't pin one — fixed by pinning `target: runner` explicitly. Verified with typecheck, lint, and three separate `docker build --target` runs (runner/cron/migrator) plus `docker compose config` validation. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@ import { headers } from "next/headers";
|
||||
import Link from "next/link";
|
||||
import { ChevronLeft, ChevronRight, ShoppingCart, Printer } from "lucide-react";
|
||||
import { auth } from "@/lib/auth/server";
|
||||
import { db, mealPlans, mealPlanMembers, recipes, eq, and, desc } from "@epicure/db";
|
||||
import { db, mealPlans, mealPlanMembers, recipes, userNutritionGoals, eq, and, desc } from "@epicure/db";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { MealPlanner } from "@/components/meal-plan/meal-planner";
|
||||
import { ShareMealPlanButton } from "@/components/meal-plan/share-meal-plan-button";
|
||||
@@ -52,7 +52,7 @@ export default async function MealPlanPage({
|
||||
const sunday = addWeeks(monday, 1);
|
||||
sunday.setDate(sunday.getDate() - 1);
|
||||
|
||||
const [plan, userRecipes, sharedMemberships] = await Promise.all([
|
||||
const [plan, userRecipes, sharedMemberships, nutritionGoals] = await Promise.all([
|
||||
db.query.mealPlans.findFirst({
|
||||
where: and(eq(mealPlans.userId, session.user.id), eq(mealPlans.weekStart, weekStart)),
|
||||
with: {
|
||||
@@ -70,8 +70,16 @@ export default async function MealPlanPage({
|
||||
where: eq(mealPlanMembers.userId, session.user.id),
|
||||
with: { mealPlan: { with: { user: true } } },
|
||||
}),
|
||||
db.query.userNutritionGoals.findFirst({
|
||||
where: eq(userNutritionGoals.userId, session.user.id),
|
||||
}),
|
||||
]);
|
||||
|
||||
const hasNutritionGoals = !!(
|
||||
nutritionGoals &&
|
||||
(nutritionGoals.caloriesKcal || nutritionGoals.proteinG || nutritionGoals.carbsG || nutritionGoals.fatG)
|
||||
);
|
||||
|
||||
const entries = (plan?.entries ?? []).map((e) => ({
|
||||
id: e.id,
|
||||
day: e.day,
|
||||
@@ -114,7 +122,7 @@ export default async function MealPlanPage({
|
||||
</div>
|
||||
|
||||
<WeeklyNutritionBar weekStart={weekStart} />
|
||||
<MealPlanner weekStart={weekStart} initialEntries={entries} userRecipes={userRecipes} />
|
||||
<MealPlanner weekStart={weekStart} initialEntries={entries} userRecipes={userRecipes} hasNutritionGoals={hasNutritionGoals} />
|
||||
|
||||
{sharedMemberships.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import type { Metadata } from "next";
|
||||
import { headers } from "next/headers";
|
||||
import { auth } from "@/lib/auth/server";
|
||||
import { NutritionDiary } from "@/components/nutrition/nutrition-diary";
|
||||
import { getMessages } from "@/lib/i18n/server";
|
||||
|
||||
export const metadata: Metadata = {};
|
||||
|
||||
export default async function NutritionDiaryPage() {
|
||||
const session = await auth.api.getSession({ headers: await headers() });
|
||||
if (!session) return null;
|
||||
const m = getMessages((session.user as { locale?: string }).locale);
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{m.nutritionDiary.title}</h1>
|
||||
<p className="text-muted-foreground mt-1">{m.nutritionDiary.subtitle}</p>
|
||||
</div>
|
||||
<NutritionDiary />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -51,7 +51,7 @@ export default async function PantryPage() {
|
||||
<div className="space-y-6">
|
||||
<PantryPageHeader items={mappedItems} />
|
||||
<ExpiringSoonSuggestions suggestions={suggestions} />
|
||||
<PantryManager initialItems={mappedItems} />
|
||||
<PantryManager key={mappedItems.map((i) => i.id).join(",")} initialItems={mappedItems} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,10 +30,13 @@ export default async function CookPage({ params }: Params) {
|
||||
|
||||
if (!recipe || recipe.steps.length === 0) notFound();
|
||||
|
||||
const unitPref = (session.user as { unitPref?: string }).unitPref === "imperial" ? "imperial" : "metric";
|
||||
|
||||
return (
|
||||
<CookingMode
|
||||
recipeId={id}
|
||||
recipeTitle={recipe.title}
|
||||
unitPref={unitPref}
|
||||
steps={recipe.steps.map((s) => ({
|
||||
id: s.id,
|
||||
instruction: s.instruction,
|
||||
|
||||
@@ -58,6 +58,7 @@ export default async function RecipePage({ params }: Params) {
|
||||
const m = getMessages((session.user as { locale?: string }).locale);
|
||||
const VISIBILITY_LABEL = m.recipe.visibility;
|
||||
const DIETARY_LABELS = m.recipe.dietary;
|
||||
const unitPref = (session.user as { unitPref?: string }).unitPref === "imperial" ? "imperial" : "metric";
|
||||
|
||||
const [recipe, ratingData, favoriteData, myRating, forkedFrom, myNote] = await Promise.all([
|
||||
db.query.recipes.findFirst({
|
||||
@@ -346,6 +347,7 @@ export default async function RecipePage({ params }: Params) {
|
||||
<ServingScaler
|
||||
baseServings={recipe.baseServings}
|
||||
recipeTitle={recipe.title}
|
||||
unitPref={unitPref}
|
||||
ingredients={recipe.ingredients.map((ing) => ({
|
||||
id: ing.id,
|
||||
rawName: ing.rawName,
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { headers } from "next/headers";
|
||||
import { auth } from "@/lib/auth/server";
|
||||
import { db, userNutritionGoals, eq } from "@epicure/db";
|
||||
import { NutritionGoalsForm } from "@/components/nutrition/nutrition-goals-form";
|
||||
import { getMessages } from "@/lib/i18n/server";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export const metadata: Metadata = {};
|
||||
|
||||
@@ -38,6 +41,15 @@ export default async function NutritionPage() {
|
||||
}
|
||||
/>
|
||||
</section>
|
||||
<section className="rounded-xl border p-6 space-y-3">
|
||||
<div>
|
||||
<h2 className="font-semibold text-lg">{m.nutritionDiary.title}</h2>
|
||||
<p className="text-sm text-muted-foreground mt-1">{m.nutritionDiary.subtitle}</p>
|
||||
</div>
|
||||
<Link href="/nutrition" className={cn(buttonVariants({ variant: "outline", size: "sm" }))}>
|
||||
{m.settings.nutritionGoals.viewDiaryCta}
|
||||
</Link>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,10 +9,13 @@ import {
|
||||
recipes,
|
||||
userFollows,
|
||||
userBlocks,
|
||||
cookingHistory,
|
||||
ratings,
|
||||
eq,
|
||||
and,
|
||||
desc,
|
||||
count,
|
||||
isNotNull,
|
||||
} from "@epicure/db";
|
||||
import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
@@ -20,14 +23,32 @@ import { FollowButton } from "@/components/social/follow-button";
|
||||
import { BlockButton } from "@/components/social/block-button";
|
||||
import { MessageButton } from "@/components/social/message-button";
|
||||
import { getPublicUrl } from "@/lib/storage";
|
||||
import { ProfileTabs, type HistoryData, type PhotosData } from "@/components/profile/profile-tabs";
|
||||
|
||||
const PAGE_SIZE = 24;
|
||||
|
||||
type Params = {
|
||||
params: Promise<{ username: string }>;
|
||||
searchParams: Promise<{ page?: string }>;
|
||||
searchParams: Promise<{ page?: string; tab?: string; ppage?: string }>;
|
||||
};
|
||||
|
||||
/** Consecutive-day streak (UTC calendar days) ending today or yesterday. */
|
||||
function computeStreak(dates: Date[]): number {
|
||||
const daySet = new Set(dates.map((d) => d.toISOString().slice(0, 10)));
|
||||
const cursor = new Date();
|
||||
cursor.setUTCHours(0, 0, 0, 0);
|
||||
if (!daySet.has(cursor.toISOString().slice(0, 10))) {
|
||||
cursor.setUTCDate(cursor.getUTCDate() - 1);
|
||||
if (!daySet.has(cursor.toISOString().slice(0, 10))) return 0;
|
||||
}
|
||||
let streak = 0;
|
||||
while (daySet.has(cursor.toISOString().slice(0, 10))) {
|
||||
streak++;
|
||||
cursor.setUTCDate(cursor.getUTCDate() - 1);
|
||||
}
|
||||
return streak;
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: Params) {
|
||||
const { username } = await params;
|
||||
const user = await db.query.users.findFirst({ where: eq(users.username, username) });
|
||||
@@ -36,9 +57,12 @@ export async function generateMetadata({ params }: Params) {
|
||||
|
||||
export default async function UserProfilePage({ params, searchParams }: Params) {
|
||||
const { username } = await params;
|
||||
const { page: pageParam } = await searchParams;
|
||||
const { page: pageParam, tab: tabParam, ppage: ppageParam } = await searchParams;
|
||||
const page = Math.max(1, parseInt(pageParam ?? "1", 10) || 1);
|
||||
const offset = (page - 1) * PAGE_SIZE;
|
||||
const photoPage = Math.max(1, parseInt(ppageParam ?? "1", 10) || 1);
|
||||
const photoOffset = (photoPage - 1) * PAGE_SIZE;
|
||||
const activeTab = tabParam === "history" || tabParam === "photos" ? tabParam : "recipes";
|
||||
|
||||
const session = await auth.api.getSession({ headers: await headers() });
|
||||
|
||||
@@ -96,6 +120,89 @@ export default async function UserProfilePage({ params, searchParams }: Params)
|
||||
isBlocked = !!blockRow;
|
||||
}
|
||||
|
||||
// Cooking history and "cooked it" photo gallery are only meaningful (and visible) to the
|
||||
// profile owner: history reveals private behavioral/timing patterns, and photos may be
|
||||
// attached to reviews of recipes that aren't visible to other viewers (private recipes),
|
||||
// so surfacing them to non-owners could leak the existence of content they can't access.
|
||||
let historyData: HistoryData | null = null;
|
||||
let photosData: PhotosData | null = null;
|
||||
|
||||
if (isOwnProfile) {
|
||||
const [totalCookedRow, cookedDatesRows, lastCookedRow, recentEntries, totalPhotosRow, photoRows] =
|
||||
await Promise.all([
|
||||
db.select({ count: count() }).from(cookingHistory).where(eq(cookingHistory.userId, user.id)),
|
||||
db.query.cookingHistory.findMany({
|
||||
where: eq(cookingHistory.userId, user.id),
|
||||
columns: { cookedAt: true },
|
||||
orderBy: desc(cookingHistory.cookedAt),
|
||||
limit: 3650,
|
||||
}),
|
||||
db.query.cookingHistory.findFirst({
|
||||
where: eq(cookingHistory.userId, user.id),
|
||||
orderBy: desc(cookingHistory.cookedAt),
|
||||
with: { recipe: { columns: { id: true, title: true } } },
|
||||
}),
|
||||
db.query.cookingHistory.findMany({
|
||||
where: eq(cookingHistory.userId, user.id),
|
||||
orderBy: desc(cookingHistory.cookedAt),
|
||||
limit: 20,
|
||||
with: { recipe: { columns: { id: true, title: true } } },
|
||||
}),
|
||||
db
|
||||
.select({ count: count() })
|
||||
.from(ratings)
|
||||
.where(and(eq(ratings.userId, user.id), isNotNull(ratings.photoKey))),
|
||||
db.query.ratings.findMany({
|
||||
where: and(eq(ratings.userId, user.id), isNotNull(ratings.photoKey)),
|
||||
orderBy: desc(ratings.createdAt),
|
||||
limit: PAGE_SIZE,
|
||||
offset: photoOffset,
|
||||
with: { recipe: { columns: { id: true, title: true } } },
|
||||
}),
|
||||
]);
|
||||
|
||||
const totalCooked = totalCookedRow[0]?.count ?? 0;
|
||||
const streak = computeStreak(cookedDatesRows.map((r) => r.cookedAt));
|
||||
const totalPhotos = totalPhotosRow[0]?.count ?? 0;
|
||||
|
||||
historyData = {
|
||||
totalCooked,
|
||||
streak,
|
||||
lastCooked:
|
||||
lastCookedRow && lastCookedRow.recipe
|
||||
? {
|
||||
recipeId: lastCookedRow.recipe.id,
|
||||
recipeTitle: lastCookedRow.recipe.title,
|
||||
cookedAt: lastCookedRow.cookedAt.toISOString(),
|
||||
}
|
||||
: null,
|
||||
recentEntries: recentEntries
|
||||
.filter((e) => e.recipe)
|
||||
.map((e) => ({
|
||||
id: e.id,
|
||||
recipeId: e.recipe!.id,
|
||||
recipeTitle: e.recipe!.title,
|
||||
cookedAt: e.cookedAt.toISOString(),
|
||||
servings: e.servings,
|
||||
})),
|
||||
};
|
||||
|
||||
photosData = {
|
||||
items: photoRows
|
||||
.filter((r) => r.recipe && r.photoKey)
|
||||
.map((r) => ({
|
||||
id: r.id,
|
||||
recipeId: r.recipe!.id,
|
||||
recipeTitle: r.recipe!.title,
|
||||
photoKey: r.photoKey!,
|
||||
createdAt: r.createdAt.toISOString(),
|
||||
})),
|
||||
page: photoPage,
|
||||
totalPages: Math.max(1, Math.ceil(totalPhotos / PAGE_SIZE)),
|
||||
total: totalPhotos,
|
||||
};
|
||||
}
|
||||
|
||||
const initials = user.name
|
||||
.split(" ")
|
||||
.slice(0, 2)
|
||||
@@ -103,6 +210,72 @@ export default async function UserProfilePage({ params, searchParams }: Params)
|
||||
.join("")
|
||||
.toUpperCase();
|
||||
|
||||
const recipesSection =
|
||||
publicRecipes.length > 0 ? (
|
||||
<div className="space-y-4">
|
||||
<h2 className="text-xl font-semibold">Recipes</h2>
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-4">
|
||||
{publicRecipes.map((recipe) => {
|
||||
const cover = recipe.photos[0];
|
||||
return (
|
||||
<Link
|
||||
key={recipe.id}
|
||||
href={`/recipes/${recipe.id}`}
|
||||
className="group block rounded-xl overflow-hidden border bg-card hover:shadow-md transition-shadow"
|
||||
>
|
||||
<div className="relative aspect-square bg-muted overflow-hidden">
|
||||
{cover ? (
|
||||
<Image
|
||||
src={getPublicUrl(cover.storageKey)}
|
||||
alt={recipe.title}
|
||||
fill
|
||||
sizes="(max-width: 640px) 50vw, (max-width: 768px) 33vw, 25vw"
|
||||
className="object-cover group-hover:scale-105 transition-transform duration-200"
|
||||
/>
|
||||
) : (
|
||||
<div className="w-full h-full flex items-center justify-center text-muted-foreground text-3xl">
|
||||
🍽️
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="p-2">
|
||||
<p className="text-sm font-medium leading-tight line-clamp-2">{recipe.title}</p>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{totalPages > 1 && (
|
||||
<div className="flex items-center justify-center gap-2 pt-2">
|
||||
{page > 1 && (
|
||||
<Link
|
||||
href={`/u/${username}${page - 1 > 1 ? `?page=${page - 1}` : ""}`}
|
||||
className="rounded-md border px-3 py-1.5 text-sm hover:bg-accent"
|
||||
>
|
||||
Previous
|
||||
</Link>
|
||||
)}
|
||||
<span className="text-sm text-muted-foreground px-2">
|
||||
Page {page} of {totalPages}
|
||||
</span>
|
||||
{page < totalPages && (
|
||||
<Link
|
||||
href={`/u/${username}?page=${page + 1}`}
|
||||
className="rounded-md border px-3 py-1.5 text-sm hover:bg-accent"
|
||||
>
|
||||
Next
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-16 text-muted-foreground">
|
||||
<p className="text-lg">No public recipes yet.</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="max-w-4xl mx-auto space-y-10">
|
||||
{/* Profile header */}
|
||||
@@ -149,70 +322,17 @@ export default async function UserProfilePage({ params, searchParams }: Params)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Recipe grid */}
|
||||
{publicRecipes.length > 0 ? (
|
||||
<div className="space-y-4">
|
||||
<h2 className="text-xl font-semibold">Recipes</h2>
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-4">
|
||||
{publicRecipes.map((recipe) => {
|
||||
const cover = recipe.photos[0];
|
||||
return (
|
||||
<Link
|
||||
key={recipe.id}
|
||||
href={`/recipes/${recipe.id}`}
|
||||
className="group block rounded-xl overflow-hidden border bg-card hover:shadow-md transition-shadow"
|
||||
>
|
||||
<div className="relative aspect-square bg-muted overflow-hidden">
|
||||
{cover ? (
|
||||
<Image
|
||||
src={getPublicUrl(cover.storageKey)}
|
||||
alt={recipe.title}
|
||||
fill
|
||||
sizes="(max-width: 640px) 50vw, (max-width: 768px) 33vw, 25vw"
|
||||
className="object-cover group-hover:scale-105 transition-transform duration-200"
|
||||
/>
|
||||
) : (
|
||||
<div className="w-full h-full flex items-center justify-center text-muted-foreground text-3xl">
|
||||
🍽️
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="p-2">
|
||||
<p className="text-sm font-medium leading-tight line-clamp-2">{recipe.title}</p>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{totalPages > 1 && (
|
||||
<div className="flex items-center justify-center gap-2 pt-2">
|
||||
{page > 1 && (
|
||||
<Link
|
||||
href={`/u/${username}${page - 1 > 1 ? `?page=${page - 1}` : ""}`}
|
||||
className="rounded-md border px-3 py-1.5 text-sm hover:bg-accent"
|
||||
>
|
||||
Previous
|
||||
</Link>
|
||||
)}
|
||||
<span className="text-sm text-muted-foreground px-2">
|
||||
Page {page} of {totalPages}
|
||||
</span>
|
||||
{page < totalPages && (
|
||||
<Link
|
||||
href={`/u/${username}?page=${page + 1}`}
|
||||
className="rounded-md border px-3 py-1.5 text-sm hover:bg-accent"
|
||||
>
|
||||
Next
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{/* Recipes / cooking history / photos */}
|
||||
{isOwnProfile && historyData && photosData ? (
|
||||
<ProfileTabs
|
||||
username={username}
|
||||
defaultTab={activeTab}
|
||||
recipesContent={recipesSection}
|
||||
history={historyData}
|
||||
photos={photosData}
|
||||
/>
|
||||
) : (
|
||||
<div className="text-center py-16 text-muted-foreground">
|
||||
<p className="text-lg">No public recipes yet.</p>
|
||||
</div>
|
||||
recipesSection
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user