aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/admin/friends/friend-list/friend-list.component.ts
blob: afbb48c1c348f0b8234f16f042ed7eb10b9f35ff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Component, OnInit } from '@angular/core';

import { Friend, FriendService } from '../shared';

@Component({
  selector: 'my-friend-list',
  templateUrl: './friend-list.component.html',
  styleUrls: [ './friend-list.component.scss' ]
})
export class FriendListComponent implements OnInit {
  friends: Friend[];

  constructor(private friendService: FriendService) {  }

  ngOnInit() {
    this.getFriends();
  }

  quitFriends() {
    if (!confirm('Are you sure?')) return;

    this.friendService.quitFriends().subscribe(
      status => {
        alert('Quit friends!');
        this.getFriends();
      },
      error => alert(error)
    );
  }

  private getFriends() {
    this.friendService.getFriends().subscribe(
      friends => this.friends = friends,

      err => alert(err)
    );
  }
}