79cdb8cd04
People search existed but was buried in its own tab with no entry point from anywhere else — easy to conclude it "doesn't work" since nobody would find it. Now one query on Explore hits both /api/v1/search and /api/v1/users/search and renders People/Recipes sections together; the standalone people tab and its now-dead PeopleSearch component are gone. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
87 lines
2.1 KiB
TypeScript
87 lines
2.1 KiB
TypeScript
import type { Metadata } from "next";
|
|
import {
|
|
db,
|
|
recipes,
|
|
users,
|
|
favorites,
|
|
eq,
|
|
desc,
|
|
sql,
|
|
and,
|
|
gte,
|
|
count,
|
|
} from "@epicure/db";
|
|
import { ExplorePageContent } from "@/components/search/explore-page-content";
|
|
|
|
export const metadata: Metadata = {};
|
|
|
|
export type RecipeResult = {
|
|
id: string;
|
|
title: string;
|
|
authorName: string | null;
|
|
difficulty: string | null;
|
|
prepMins: number | null;
|
|
cookMins: number | null;
|
|
};
|
|
|
|
export default async function ExplorePage({
|
|
searchParams,
|
|
}: {
|
|
searchParams: Promise<{ q?: string }>;
|
|
}) {
|
|
const { q } = await searchParams;
|
|
const sevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
|
|
|
|
// Trending: public recipes ordered by favorite count in last 7 days
|
|
const trendingRows = await db
|
|
.select({
|
|
id: recipes.id,
|
|
title: recipes.title,
|
|
authorName: users.name,
|
|
difficulty: recipes.difficulty,
|
|
prepMins: recipes.prepMins,
|
|
cookMins: recipes.cookMins,
|
|
favoriteCount: count(favorites.recipeId),
|
|
})
|
|
.from(recipes)
|
|
.innerJoin(users, eq(recipes.authorId, users.id))
|
|
.leftJoin(
|
|
favorites,
|
|
and(
|
|
eq(favorites.recipeId, recipes.id),
|
|
gte(favorites.createdAt, sevenDaysAgo)
|
|
)
|
|
)
|
|
.where(and(eq(recipes.visibility, "public"), eq(users.isPrivate, false)))
|
|
.groupBy(recipes.id, users.id)
|
|
.orderBy(desc(sql`count(${favorites.recipeId})`))
|
|
.limit(12);
|
|
|
|
// Recent: public recipes ordered by createdAt desc
|
|
const recentRows = await db
|
|
.select({
|
|
id: recipes.id,
|
|
title: recipes.title,
|
|
authorName: users.name,
|
|
difficulty: recipes.difficulty,
|
|
prepMins: recipes.prepMins,
|
|
cookMins: recipes.cookMins,
|
|
})
|
|
.from(recipes)
|
|
.innerJoin(users, eq(recipes.authorId, users.id))
|
|
.where(and(eq(recipes.visibility, "public"), eq(users.isPrivate, false)))
|
|
.orderBy(desc(recipes.createdAt))
|
|
.limit(12);
|
|
|
|
const trending: RecipeResult[] = trendingRows.map(({ favoriteCount: _fc, ...r }) => r);
|
|
const recent: RecipeResult[] = recentRows;
|
|
|
|
return (
|
|
<ExplorePageContent
|
|
trending={trending}
|
|
recent={recent}
|
|
initialQuery={q ?? ""}
|
|
/>
|
|
);
|
|
}
|