You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.8 KiB
69 lines
1.8 KiB
import { Component, OnInit } from '@angular/core';
|
|
import { FriendsService } from '../../services/friends/friends.service';
|
|
import { CommonModule } from '@angular/common';
|
|
|
|
@Component({
|
|
selector: 'app-friend-page',
|
|
imports: [CommonModule],
|
|
templateUrl: './friend-page.component.html',
|
|
styleUrls: ['./friend-page.component.css']
|
|
})
|
|
export class FriendPageComponent implements OnInit {
|
|
protected listFriend: {username: string, status: string, friend_user_id: string, id: string}[] = [];
|
|
userId: string = "";
|
|
status: string = "";
|
|
isFriendModalOpen: boolean = false;
|
|
hasAcceptedFriends: boolean = false ;
|
|
hasPendingFriends: boolean = false;
|
|
|
|
|
|
constructor(private friendService: FriendsService) {
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.getFriendData();
|
|
}
|
|
|
|
private getFriendData(): void {
|
|
this.friendService.getFriend().subscribe((data: any[]) => {
|
|
if (data.length > 0) {
|
|
data.forEach(friend => {
|
|
console.log(friend)
|
|
let status = friend['status'];
|
|
let userId = friend['friend_user_id'];
|
|
let id = friend['id'];
|
|
this.friendService.getFriendById(userId).subscribe((friendData: any) => {
|
|
this.listFriend.push({
|
|
username: friendData.username,
|
|
status: status,
|
|
friend_user_id: userId,
|
|
id: id
|
|
});
|
|
});
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
onAcceptOrDeny(id: string, choice: string){
|
|
if (choice == "accept"){
|
|
this.friendService.acceptFriendById(id).subscribe()
|
|
}
|
|
else {
|
|
this.friendService.denyFriendById(id).subscribe()
|
|
}
|
|
}
|
|
|
|
openFriendModal() {
|
|
this.isFriendModalOpen = true;
|
|
}
|
|
|
|
closeFriendModal() {
|
|
this.isFriendModalOpen = false;
|
|
}
|
|
|
|
deleteFriend(id: string){
|
|
this.friendService.deleteFriend(id).subscribe();
|
|
}
|
|
}
|