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"; import { cookies } from "next/headers"; interface ProfilePageProps { params: { username: string }; } export default async function ProfilePage({ params }: ProfilePageProps) { const { username } = params; const token = (await cookies()).get("auth_token")?.value ?? null; // 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, token), getUserThoughts(username, token), ]); // 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 (
{/* Custom CSS Injection */} {user.customCss && (