aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/friends/friend-list/friend-list.component.ts
blob: 175ad9cba8938cf489d9d9188462958a8f358c4a (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Component, OnInit } from '@angular/core';

import { NotificationsService } from 'angular2-notifications';

import { ConfirmService } from '../../../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 notificationsService: NotificationsService,
    private confirmService: ConfirmService,
    private friendService: FriendService
  ) {  }

  ngOnInit() {
    this.getFriends();
  }

  quitFriends() {
    const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.';
    this.confirmService.confirm(confirmMessage, 'Quit friends').subscribe(
      res => {
        if (res === false) return;

        this.friendService.quitFriends().subscribe(
          status => {
            this.notificationsService.success('Sucess', 'Friends left!');

            this.getFriends();
          },

          err => this.notificationsService.error('Error', err.text)
        );
      }
    );
  }

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

      err => this.notificationsService.error('Error', err.text)
    );
  }
}