diff --git a/src/components/FriendsList.tsx b/src/components/FriendsList.tsx index a155cef..d39b0cd 100644 --- a/src/components/FriendsList.tsx +++ b/src/components/FriendsList.tsx @@ -73,7 +73,7 @@ const FriendsList: React.FC = () => { const filteredUsernames = usernamesData.filter((user: any) => { return user.id !== auth.currentUser?.uid && !friends.some(friend => friend.id === user.id) && - !friendRequests.outgoing.includes(user.id); + !friendRequests.outgoing.some((u: any) => u.id === user.id); }); setAllUsernames(filteredUsernames); } catch (error) { @@ -541,37 +541,33 @@ const FriendsList: React.FC = () => {

Pending Requests

- {friendRequests.outgoing.map((userId) => { - // Find the user details from allUsernames array - const user = allUsernames.find(u => u.id === userId); - return ( -
-
- - {user ? getInitials(user) : 'U'} - -
-
-

{user ? `${user.firstName} ${user.lastName}` : 'User'}

- - Pending - -
-

{user ? `@${user.username}` : ''}

+ {friendRequests.outgoing.map((outgoingUser) => ( +
+
+ + {getInitials(outgoingUser)} + +
+
+

{outgoingUser.firstName} {outgoingUser.lastName}

+ + Pending +
+

@{outgoingUser.username}

-
- ); - })} + +
+ ))}
)} diff --git a/src/utils/auth.tsx b/src/utils/auth.tsx index f5400bd..5fd471b 100644 --- a/src/utils/auth.tsx +++ b/src/utils/auth.tsx @@ -11,7 +11,7 @@ interface AuthContextType { firebaseInitialized: boolean; friendRequests: { incoming: UserProfile[]; - outgoing: string[]; + outgoing: UserProfile[]; }; friends: UserProfile[]; accountabilityPartners: UserProfile[]; @@ -47,7 +47,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children const [isLoading, setIsLoading] = useState(true); const [firebaseInitialized, setFirebaseInitialized] = useState(!!auth); const [isAdmin, setIsAdmin] = useState(false); - const [friendRequests, setFriendRequests] = useState<{ incoming: UserProfile[], outgoing: string[] }>({ + const [friendRequests, setFriendRequests] = useState<{ incoming: UserProfile[], outgoing: UserProfile[] }>({ incoming: [], outgoing: [] }); @@ -80,10 +80,20 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children } } } + + const outgoingRequests: UserProfile[] = []; + if (profile.friendRequests?.outgoing?.length) { + for (const recipientId of profile.friendRequests.outgoing) { + const recipientProfile = await getUserProfile(recipientId); + if (recipientProfile) { + outgoingRequests.push(recipientProfile); + } + } + } setFriendRequests({ incoming: incomingRequests, - outgoing: profile.friendRequests?.outgoing || [] + outgoing: outgoingRequests }); const friendsList: UserProfile[] = [];