]>
Commit | Line | Data |
---|---|---|
e2f555ca C |
1 | import { Component, OnInit } from '@angular/core'; |
2 | ||
7ddd02c9 C |
3 | import { NotificationsService } from 'angular2-notifications'; |
4 | ||
5769e1db | 5 | import { ConfirmService } from '../../../core'; |
e2f555ca C |
6 | import { Friend, FriendService } from '../shared'; |
7 | ||
8 | @Component({ | |
9 | selector: 'my-friend-list', | |
ec8d8440 C |
10 | templateUrl: './friend-list.component.html', |
11 | styleUrls: [ './friend-list.component.scss' ] | |
e2f555ca C |
12 | }) |
13 | export class FriendListComponent implements OnInit { | |
14 | friends: Friend[]; | |
15 | ||
7ddd02c9 C |
16 | constructor( |
17 | private notificationsService: NotificationsService, | |
5769e1db | 18 | private confirmService: ConfirmService, |
7ddd02c9 C |
19 | private friendService: FriendService |
20 | ) { } | |
e2f555ca C |
21 | |
22 | ngOnInit() { | |
93c462b7 | 23 | this.getFriends(); |
e2f555ca C |
24 | } |
25 | ||
e2f555ca | 26 | quitFriends() { |
5769e1db C |
27 | const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.'; |
28 | this.confirmService.confirm(confirmMessage, 'Quit friends').subscribe( | |
29 | res => { | |
30 | if (res === false) return; | |
e2f555ca | 31 | |
5769e1db C |
32 | this.friendService.quitFriends().subscribe( |
33 | status => { | |
34 | this.notificationsService.success('Sucess', 'Friends left!'); | |
7ddd02c9 | 35 | |
5769e1db C |
36 | this.getFriends(); |
37 | }, | |
7ddd02c9 | 38 | |
5769e1db C |
39 | err => this.notificationsService.error('Error', err.text) |
40 | ); | |
41 | } | |
e2f555ca C |
42 | ); |
43 | } | |
93c462b7 C |
44 | |
45 | private getFriends() { | |
46 | this.friendService.getFriends().subscribe( | |
55fa55a9 | 47 | res => this.friends = res.friends, |
93c462b7 | 48 | |
7ddd02c9 | 49 | err => this.notificationsService.error('Error', err.text) |
93c462b7 C |
50 | ); |
51 | } | |
e2f555ca | 52 | } |