feat: merge Explore and Activity Feed, unify recipe cards
Explore and Feed covered overlapping ground (recommendations, following, trending) in two separate places with three different card designs. Explore now hosts Discover/Following/For You tabs, and every recipe card everywhere on the page matches the Recipes page's cover-photo card instead of the old text-only search result. v0.36.0
This commit is contained in:
@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { db, recipes, users, favorites, ratings, userFollows, eq, and, or, ne, gte, notInArray, inArray, desc, isNotNull } from "@epicure/db";
|
||||
import { requireSessionOrApiKey } from "@/lib/api-auth";
|
||||
import { buildPreferenceMap, rankForYou } from "@/lib/for-you-ranking";
|
||||
import { attachCardExtras } from "@/lib/recipe-card-extras";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const { session, response } = await requireSessionOrApiKey(req);
|
||||
@@ -47,6 +48,9 @@ export async function GET(req: NextRequest) {
|
||||
authorAvatarUrl: users.avatarUrl,
|
||||
tags: recipes.tags,
|
||||
dietaryTags: recipes.dietaryTags,
|
||||
isBatchCook: recipes.isBatchCook,
|
||||
sourceUrl: recipes.sourceUrl,
|
||||
recipeType: recipes.recipeType,
|
||||
})
|
||||
.from(recipes)
|
||||
.innerJoin(users, eq(recipes.authorId, users.id))
|
||||
@@ -68,10 +72,11 @@ export async function GET(req: NextRequest) {
|
||||
? rankForYou(candidates, preferences)
|
||||
: [...candidates].sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
||||
|
||||
const data = ranked.slice(offset, offset + limit).map(({ tags: _tags, dietaryTags: _dietaryTags, ...r }) => ({
|
||||
const page = ranked.slice(offset, offset + limit).map(({ dietaryTags: _dietaryTags, ...r }) => ({
|
||||
...r,
|
||||
createdAt: r.createdAt.toISOString(),
|
||||
}));
|
||||
const data = await attachCardExtras(page, userId);
|
||||
|
||||
// `ranked` is capped to a bounded recent window (see `candidates` query above), so this
|
||||
// total reflects the size of that ranked window rather than every eligible recipe.
|
||||
|
||||
@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { db, recipes, users, userFollows, eq, and, ne, sql } from "@epicure/db";
|
||||
import { requireSessionOrApiKey } from "@/lib/api-auth";
|
||||
import { desc, inArray } from "@epicure/db";
|
||||
import { attachCardExtras } from "@/lib/recipe-card-extras";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const { session, response } = await requireSessionOrApiKey(req);
|
||||
@@ -36,6 +37,10 @@ export async function GET(req: NextRequest) {
|
||||
cookMins: recipes.cookMins,
|
||||
difficulty: recipes.difficulty,
|
||||
visibility: recipes.visibility,
|
||||
tags: recipes.tags,
|
||||
isBatchCook: recipes.isBatchCook,
|
||||
sourceUrl: recipes.sourceUrl,
|
||||
recipeType: recipes.recipeType,
|
||||
createdAt: recipes.createdAt,
|
||||
updatedAt: recipes.updatedAt,
|
||||
authorId: recipes.authorId,
|
||||
@@ -57,6 +62,7 @@ export async function GET(req: NextRequest) {
|
||||
]);
|
||||
|
||||
const total = totalRow[0]?.total ?? 0;
|
||||
const data = await attachCardExtras(feedRecipes, session!.user.id);
|
||||
|
||||
return NextResponse.json({ data: feedRecipes, total, limit, offset });
|
||||
return NextResponse.json({ data, total, limit, offset });
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
desc,
|
||||
} from "@epicure/db";
|
||||
import { getAvgRatingsByRecipeId } from "@/lib/recipe-ratings";
|
||||
import { attachCardExtras } from "@/lib/recipe-card-extras";
|
||||
import { getOptionalSession } from "@/lib/api-auth";
|
||||
|
||||
const VALID_DIETARY = ["vegan", "vegetarian", "glutenFree", "dairyFree"] as const;
|
||||
type DietaryTag = (typeof VALID_DIETARY)[number];
|
||||
@@ -130,6 +132,11 @@ export async function GET(req: NextRequest) {
|
||||
baseServings: recipes.baseServings,
|
||||
prepMins: recipes.prepMins,
|
||||
cookMins: recipes.cookMins,
|
||||
visibility: recipes.visibility,
|
||||
tags: recipes.tags,
|
||||
isBatchCook: recipes.isBatchCook,
|
||||
sourceUrl: recipes.sourceUrl,
|
||||
recipeType: recipes.recipeType,
|
||||
authorId: recipes.authorId,
|
||||
authorName: users.name,
|
||||
createdAt: recipes.createdAt,
|
||||
@@ -150,8 +157,12 @@ export async function GET(req: NextRequest) {
|
||||
|
||||
const total = countResult[0]?.total ?? 0;
|
||||
|
||||
const ratingByRecipe = await getAvgRatingsByRecipeId(rows.map((r) => r.id));
|
||||
const data = rows.map((r) => ({
|
||||
const session = await getOptionalSession();
|
||||
const [ratingByRecipe, rowsWithExtras] = await Promise.all([
|
||||
getAvgRatingsByRecipeId(rows.map((r) => r.id)),
|
||||
attachCardExtras(rows, session?.user.id),
|
||||
]);
|
||||
const data = rowsWithExtras.map((r) => ({
|
||||
...r,
|
||||
avgRating: ratingByRecipe.get(r.id)?.avgRating ?? null,
|
||||
ratingCount: ratingByRecipe.get(r.id)?.ratingCount ?? 0,
|
||||
|
||||
Reference in New Issue
Block a user