Fix list friend real time display

pull/26/head
Alix JEUDI--LEMOINE 4 months ago
parent e95582ce7b
commit ffb4fe781e

@ -47,10 +47,27 @@ export class FriendPageComponent implements OnInit {
onAcceptOrDeny(id: string, choice: string){ onAcceptOrDeny(id: string, choice: string){
if (choice == "accept"){ if (choice == "accept"){
this.friendService.acceptFriendById(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) => {
else { if (data.message == "Friend request accepted"){
this.friendService.denyFriendById(id).subscribe() 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', 'Content-Type': 'application/json',
Authorization: 'Bearer ' + localStorage.getItem('auth_token'), Authorization: 'Bearer ' + localStorage.getItem('auth_token'),
}); });
return this.http.post<any>(url, [], { headers }); return this.http.delete<any>(url, { headers });
} }
deleteFriend(id: string){ deleteFriend(id: string){

Loading…
Cancel
Save