{user.displayName || user.username}
@{user.username}
{user.bio}
This user hasn't posted any thoughts yet.
)}import { getUserProfile, getUserThoughts } from "@/lib/api"; import { UserAvatar } from "@/components/user-avatar"; import { ThoughtCard } from "@/components/thought-card"; import { Calendar } from "lucide-react"; import { Card } from "@/components/ui/card"; import { notFound } from "next/navigation"; interface ProfilePageProps { params: { username: string }; } export default async function ProfilePage({ params }: ProfilePageProps) { const { username } = params; // Fetch data directly on the server. // The `loading.tsx` file will be shown to the user during this fetch. const [userResult, thoughtsResult] = await Promise.allSettled([ getUserProfile(username), getUserThoughts(username), ]); // Handle errors from the server-side fetch if (userResult.status === "rejected") { // If the user isn't found, render the Next.js 404 page notFound(); } const user = userResult.value; const thoughts = thoughtsResult.status === "fulfilled" ? thoughtsResult.value.thoughts : []; return (
@{user.username}
{user.bio}
This user hasn't posted any thoughts yet.
)}