Fix list friend real time display

master
Alix JEUDI--LEMOINE 3 months ago
parent e95582ce7b
commit ffb4fe781e

@ -47,10 +47,27 @@ export class FriendPageComponent implements OnInit {
onAcceptOrDeny(id: string, choice: string){
if (choice == "accept"){
this.friendService.acceptFriendById(id).subscribe()
}
else {
this.friendService.denyFriendById(id).subscribe()
// If return code is 200, then the friend has been accepted so we can change the status of the friend to accepted
this.friendService.acceptFriendById(id).subscribe((data: any) => {
if (data.message == "Friend request accepted"){
this.listFriend.forEach(friend => {
if (friend.id == id){
friend.status = "accepted";
}
});
}
});
} else {
// If return code is 200, then the friend has been denied so we can delete the friend from the list
this.friendService.denyFriendById(id).subscribe((data: any) => {
if (data.message == "Friend request denied"){
this.listFriend.forEach((friend, index) => {
if (friend.id == id){
this.listFriend.splice(index, 1);
}
});
}
});
}
}

@ -45,7 +45,7 @@ export class FriendsService {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + localStorage.getItem('auth_token'),
});
return this.http.post<any>(url, [], { headers });
return this.http.delete<any>(url, { headers });
}
deleteFriend(id: string){

Loading…
Cancel
Save