diff --git a/thoughts-frontend/components/top-friends.tsx b/thoughts-frontend/components/top-friends.tsx index b7aed43..9d4f23a 100644 --- a/thoughts-frontend/components/top-friends.tsx +++ b/thoughts-frontend/components/top-friends.tsx @@ -1,51 +1,25 @@ 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 { getTopFriends } from "@/lib/api"; import { cookies } from "next/headers"; interface TopFriendsProps { - mode: "friends" | "top-friends"; - usernames: string[]; + username: string; } -export async function TopFriends({ - mode = "top-friends", - usernames, -}: TopFriendsProps) { +export async function TopFriends({ username }: TopFriendsProps) { const token = (await cookies()).get("auth_token")?.value ?? null; + const data = await getTopFriends(username, token).catch(() => ({ topFriends: [] })); + const friends = data.topFriends; - if (usernames.length === 0) { - return ( - - - Top Friends - - -

- No top friends to display. -

-
-
- ); - } - - 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); + if (friends.length === 0) return null; return ( - {mode === "top-friends" ? "Top Friends" : "Friends"} + Top Friends @@ -59,7 +33,7 @@ export async function TopFriends({ {friend.displayName || friend.username}