Skip to content

Commit 22d96b8

Browse files
authored
Merge pull request #40 from Debugging-Disciples/copilot/fix-friend-request-display
fix: Display requested friend's name in pending partner requests
2 parents 59d48c3 + 9128daa commit 22d96b8

2 files changed

Lines changed: 38 additions & 32 deletions

File tree

src/components/FriendsList.tsx

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const FriendsList: React.FC = () => {
7373
const filteredUsernames = usernamesData.filter((user: any) => {
7474
return user.id !== auth.currentUser?.uid &&
7575
!friends.some(friend => friend.id === user.id) &&
76-
!friendRequests.outgoing.includes(user.id);
76+
!friendRequests.outgoing.some((u: any) => u.id === user.id);
7777
});
7878
setAllUsernames(filteredUsernames);
7979
} catch (error) {
@@ -541,37 +541,33 @@ const FriendsList: React.FC = () => {
541541
<div className="mb-4">
542542
<h4 className="text-sm font-medium mb-2">Pending Requests</h4>
543543
<div className="space-y-2">
544-
{friendRequests.outgoing.map((userId) => {
545-
// Find the user details from allUsernames array
546-
const user = allUsernames.find(u => u.id === userId);
547-
return (
548-
<div key={userId} className="flex items-center justify-between p-2 border rounded bg-muted/10">
549-
<div className="flex items-center">
550-
<Avatar className="h-8 w-8 mr-2">
551-
<AvatarFallback>{user ? getInitials(user) : 'U'}</AvatarFallback>
552-
</Avatar>
553-
<div>
554-
<div className="flex items-center">
555-
<p className="font-medium">{user ? `${user.firstName} ${user.lastName}` : 'User'}</p>
556-
<span className="ml-2 px-1.5 py-0.5 text-xs bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 rounded">
557-
Pending
558-
</span>
559-
</div>
560-
<p className="text-xs text-muted-foreground">{user ? `@${user.username}` : ''}</p>
544+
{friendRequests.outgoing.map((outgoingUser) => (
545+
<div key={outgoingUser.id} className="flex items-center justify-between p-2 border rounded bg-muted/10">
546+
<div className="flex items-center">
547+
<Avatar className="h-8 w-8 mr-2">
548+
<AvatarFallback>{getInitials(outgoingUser)}</AvatarFallback>
549+
</Avatar>
550+
<div>
551+
<div className="flex items-center">
552+
<p className="font-medium">{outgoingUser.firstName} {outgoingUser.lastName}</p>
553+
<span className="ml-2 px-1.5 py-0.5 text-xs bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 rounded">
554+
Pending
555+
</span>
561556
</div>
557+
<p className="text-xs text-muted-foreground">@{outgoingUser.username}</p>
562558
</div>
563-
<Button
564-
size="sm"
565-
variant="outline"
566-
onClick={() => handleCancelFriendRequest(userId)}
567-
title="Cancel request"
568-
className="h-8 w-8 p-0"
569-
>
570-
<X className="h-4 w-4" />
571-
</Button>
572559
</div>
573-
);
574-
})}
560+
<Button
561+
size="sm"
562+
variant="outline"
563+
onClick={() => handleCancelFriendRequest(outgoingUser.id)}
564+
title="Cancel request"
565+
className="h-8 w-8 p-0"
566+
>
567+
<X className="h-4 w-4" />
568+
</Button>
569+
</div>
570+
))}
575571
</div>
576572
</div>
577573
)}

src/utils/auth.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface AuthContextType {
1111
firebaseInitialized: boolean;
1212
friendRequests: {
1313
incoming: UserProfile[];
14-
outgoing: string[];
14+
outgoing: UserProfile[];
1515
};
1616
friends: UserProfile[];
1717
accountabilityPartners: UserProfile[];
@@ -47,7 +47,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
4747
const [isLoading, setIsLoading] = useState(true);
4848
const [firebaseInitialized, setFirebaseInitialized] = useState(!!auth);
4949
const [isAdmin, setIsAdmin] = useState(false);
50-
const [friendRequests, setFriendRequests] = useState<{ incoming: UserProfile[], outgoing: string[] }>({
50+
const [friendRequests, setFriendRequests] = useState<{ incoming: UserProfile[], outgoing: UserProfile[] }>({
5151
incoming: [],
5252
outgoing: []
5353
});
@@ -80,10 +80,20 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
8080
}
8181
}
8282
}
83+
84+
const outgoingRequests: UserProfile[] = [];
85+
if (profile.friendRequests?.outgoing?.length) {
86+
for (const recipientId of profile.friendRequests.outgoing) {
87+
const recipientProfile = await getUserProfile(recipientId);
88+
if (recipientProfile) {
89+
outgoingRequests.push(recipientProfile);
90+
}
91+
}
92+
}
8393

8494
setFriendRequests({
8595
incoming: incomingRequests,
86-
outgoing: profile.friendRequests?.outgoing || []
96+
outgoing: outgoingRequests
8797
});
8898

8999
const friendsList: UserProfile[] = [];

0 commit comments

Comments
 (0)