import Link from "next/link";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { UserAvatar } from "./user-avatar";
import { getUserProfile, User } from "@/lib/api";
import { cookies } from "next/headers";
interface TopFriendsProps {
usernames: string[];
}
// This is an async Server Component
export async function TopFriends({ usernames }: TopFriendsProps) {
const token = (await cookies()).get("auth_token")?.value ?? null;
if (usernames.length === 0) {
return (
Top Friends
No top friends to display.
);
}
// Fetch all top friend profiles in parallel
const friendsResults = await Promise.allSettled(
usernames.map((username) => getUserProfile(username, token))
);
const friends = friendsResults
.filter(
(result): result is PromiseFulfilledResult =>
result.status === "fulfilled"
)
.map((result) => result.value);
return (
Top Friends
{friends.map((friend) => (
{friend.displayName || friend.username}
))}
);
}