feat(social): follows, favorites, comments, reactions, collections, public profiles
Follow/unfollow users. Recipe favorites. Threaded comments with emoji reactions. Collections (public/private) with shared member invite. Activity feed. Public profile pages at /u/[username].
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import type { Metadata } from "next";
|
||||
import { headers } from "next/headers";
|
||||
import { auth } from "@/lib/auth/server";
|
||||
import { db, recipes, users, userFollows, eq, desc, inArray } from "@epicure/db";
|
||||
import { getPublicUrl } from "@/lib/storage";
|
||||
import { FeedPageContent } from "@/components/feed/feed-page-content";
|
||||
|
||||
export const metadata: Metadata = { title: "Feed" };
|
||||
|
||||
export default async function FeedPage() {
|
||||
const session = await auth.api.getSession({ headers: await headers() });
|
||||
if (!session) return null;
|
||||
|
||||
const followedRows = await db
|
||||
.select({ followingId: userFollows.followingId })
|
||||
.from(userFollows)
|
||||
.where(eq(userFollows.followerId, session.user.id));
|
||||
|
||||
const followedIds = followedRows.map((r) => r.followingId);
|
||||
|
||||
if (followedIds.length === 0) {
|
||||
return <FeedPageContent followedCount={0} feedRecipes={[]} />;
|
||||
}
|
||||
|
||||
const feedRecipes = await db
|
||||
.select({
|
||||
id: recipes.id,
|
||||
title: recipes.title,
|
||||
description: recipes.description,
|
||||
baseServings: recipes.baseServings,
|
||||
prepMins: recipes.prepMins,
|
||||
cookMins: recipes.cookMins,
|
||||
difficulty: recipes.difficulty,
|
||||
visibility: recipes.visibility,
|
||||
aiGenerated: recipes.aiGenerated,
|
||||
createdAt: recipes.createdAt,
|
||||
authorId: recipes.authorId,
|
||||
authorName: users.name,
|
||||
authorUsername: users.username,
|
||||
authorAvatarUrl: users.avatarUrl,
|
||||
})
|
||||
.from(recipes)
|
||||
.innerJoin(users, eq(recipes.authorId, users.id))
|
||||
.where(inArray(recipes.authorId, followedIds))
|
||||
.orderBy(desc(recipes.createdAt))
|
||||
.limit(40);
|
||||
|
||||
return (
|
||||
<FeedPageContent
|
||||
followedCount={followedIds.length}
|
||||
feedRecipes={feedRecipes.map((r) => ({ ...r, createdAt: r.createdAt.toISOString() }))}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user