From a279988d396adc400c438374e8be3bf757ebc0ae Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Thu, 28 May 2026 22:52:09 +0200 Subject: [PATCH] feat: add ProfileFriendsWidget with top-friends/all-friends conditional --- .../components/profile-friends-widget.tsx | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 thoughts-frontend/components/profile-friends-widget.tsx diff --git a/thoughts-frontend/components/profile-friends-widget.tsx b/thoughts-frontend/components/profile-friends-widget.tsx new file mode 100644 index 0000000..c4a333b --- /dev/null +++ b/thoughts-frontend/components/profile-friends-widget.tsx @@ -0,0 +1,37 @@ +import { getTopFriends, getMyFriends, getMyRemoteFriends } from "@/lib/api"; +import { TopFriends } from "./top-friends"; +import { AllFriendsCard } from "./all-friends-card"; + +interface ProfileFriendsWidgetProps { + username: string; + isOwnProfile: boolean; + token: string | null; +} + +export async function ProfileFriendsWidget({ + username, + isOwnProfile, + token, +}: ProfileFriendsWidgetProps) { + const topFriendsData = await getTopFriends(username, token).catch(() => ({ + topFriends: [], + })); + + if (topFriendsData.topFriends.length > 0) { + return ; + } + + if (!isOwnProfile || !token) return null; + + const [localData, remoteData] = await Promise.all([ + getMyFriends(token).catch(() => ({ items: [], total: 0, page: 1, perPage: 50 })), + getMyRemoteFriends(token).catch(() => []), + ]); + + return ( + + ); +}