import { getMe, getUserProfile, getUserThoughts, Me } from "@/lib/api"; import { UserAvatar } from "@/components/user-avatar"; import { Calendar, Settings } from "lucide-react"; import { Card } from "@/components/ui/card"; import { notFound } from "next/navigation"; import { cookies } from "next/headers"; import { FollowButton } from "@/components/follow-button"; import { TopFriends } from "@/components/top-friends"; import { buildThoughtThreads } from "@/lib/utils"; import { ThoughtThread } from "@/components/thought-thread"; import { Button } from "@/components/ui/button"; import Link from "next/link"; interface ProfilePageProps { params: { username: string }; } export default async function ProfilePage({ params }: ProfilePageProps) { const { username } = params; const token = (await cookies()).get("auth_token")?.value ?? null; const userProfilePromise = getUserProfile(username, token); const thoughtsPromise = getUserThoughts(username, token); const mePromise = token ? getMe(token) : Promise.resolve(null); const [userResult, thoughtsResult, meResult] = await Promise.allSettled([ userProfilePromise, thoughtsPromise, mePromise, ]); if (userResult.status === "rejected") { notFound(); } const user = userResult.value; const me = meResult.status === "fulfilled" ? (meResult.value as Me) : null; const thoughts = thoughtsResult.status === "fulfilled" ? thoughtsResult.value.thoughts : []; const { topLevelThoughts, repliesByParentId } = buildThoughtThreads(thoughts); const isOwnProfile = me?.username === user.username; const isFollowing = me?.following?.some( (followedUser) => followedUser.username === user.username ) || false; const authorDetails = new Map(); authorDetails.set(user.username, { avatarUrl: user.avatarUrl }); return (
{user.customCss && (