From ffb4fe781ed680a8ed28a1681cb5298f670dc70a Mon Sep 17 00:00:00 2001 From: Alix JEUDI--LEMOINE Date: Mon, 10 Feb 2025 11:09:14 +0100 Subject: [PATCH] :sparkles: Fix list friend real time display --- .../friend-page/friend-page.component.ts | 25 ++++++++++++++++--- src/app/services/friends/friends.service.ts | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/app/components/friend-page/friend-page.component.ts b/src/app/components/friend-page/friend-page.component.ts index daa0cc2..878ceab 100644 --- a/src/app/components/friend-page/friend-page.component.ts +++ b/src/app/components/friend-page/friend-page.component.ts @@ -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); + } + }); + } + }); } } diff --git a/src/app/services/friends/friends.service.ts b/src/app/services/friends/friends.service.ts index d183042..8bd49a1 100644 --- a/src/app/services/friends/friends.service.ts +++ b/src/app/services/friends/friends.service.ts @@ -45,7 +45,7 @@ export class FriendsService { 'Content-Type': 'application/json', Authorization: 'Bearer ' + localStorage.getItem('auth_token'), }); - return this.http.post(url, [], { headers }); + return this.http.delete(url, { headers }); } deleteFriend(id: string){