diff --git a/src/app/profile/[profileId]/page.tsx b/src/app/profile/[profileId]/page.tsx index 37412a3..78b12f5 100644 --- a/src/app/profile/[profileId]/page.tsx +++ b/src/app/profile/[profileId]/page.tsx @@ -1,6 +1,6 @@ import Link from "next/link"; import { db } from "~/server/db"; -import { profiles, posts } from "~/server/db/schema"; +import { profiles, posts, savedPosts } from "~/server/db/schema"; import { eq, desc } from "drizzle-orm"; import { getSessionUser } from "~/server/auth"; import { notFound } from "next/navigation"; @@ -10,8 +10,10 @@ import { notFound } from "next/navigation"; export default async function ProfilePage({ params, + searchParams, }: { params: Promise<{ profileId: string }>; + searchParams: Promise<{ tab?: string }>; }) { const session = await getSessionUser({ with: { @@ -32,6 +34,9 @@ export default async function ProfilePage({ }, }); const { profileId } = await params; + const { tab } = await searchParams; + const activeTab = tab === "saved" ? "saved" : "posts"; + const isOwnProfile = session?.userId === profileId; const isSignedIn = session && @@ -70,6 +75,16 @@ export default async function ProfilePage({ .where(eq(posts.authorId, profile.id)) .orderBy(desc(posts.createdAt)); + // Only fetch saved posts if viewing own profile + const savedPostsResult = isOwnProfile + ? await db + .select({ post: posts }) + .from(savedPosts) + .innerJoin(posts, eq(posts.id, savedPosts.postId)) + .where(eq(savedPosts.userId, session.userId)) + .orderBy(desc(savedPosts.createdAt)) + : []; + return (