]>
Commit | Line | Data |
---|---|---|
60862425 | 1 | import { Component } from '@angular/core' |
51548b31 C |
2 | import { NotificationsService } from 'angular2-notifications' |
3 | import { SortMeta } from 'primeng/primeng' | |
50d6de9c | 4 | import { AccountFollow } from '../../../../../../shared/models/actors/follow.model' |
7e9334c3 | 5 | import { ConfirmService } from '../../../core/confirm/confirm.service' |
60862425 | 6 | import { RestPagination, RestTable } from '../../../shared' |
51548b31 C |
7 | import { FollowService } from '../shared' |
8 | ||
9 | @Component({ | |
10 | selector: 'my-followers-list', | |
11 | templateUrl: './following-list.component.html' | |
12 | }) | |
13 | export class FollowingListComponent extends RestTable { | |
60862425 | 14 | following: AccountFollow[] = [] |
51548b31 C |
15 | totalRecords = 0 |
16 | rowsPerPage = 10 | |
17 | sort: SortMeta = { field: 'createdAt', order: 1 } | |
18 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
19 | ||
20 | constructor ( | |
21 | private notificationsService: NotificationsService, | |
7e9334c3 | 22 | private confirmService: ConfirmService, |
51548b31 C |
23 | private followService: FollowService |
24 | ) { | |
25 | super() | |
26 | } | |
27 | ||
1f30a185 C |
28 | async removeFollowing (follow: AccountFollow) { |
29 | const res = await this.confirmService.confirm(`Do you really want to unfollow ${follow.following.host}?`, 'Unfollow') | |
30 | if (res === false) return | |
7e9334c3 | 31 | |
1f30a185 C |
32 | this.followService.unfollow(follow).subscribe( |
33 | () => { | |
34 | this.notificationsService.success('Success', `You are not following ${follow.following.host} anymore.`) | |
35 | this.loadData() | |
36 | }, | |
7e9334c3 | 37 | |
1f30a185 | 38 | err => this.notificationsService.error('Error', err.message) |
7e9334c3 C |
39 | ) |
40 | } | |
41 | ||
51548b31 C |
42 | protected loadData () { |
43 | this.followService.getFollowing(this.pagination, this.sort) | |
44 | .subscribe( | |
45 | resultList => { | |
46 | this.following = resultList.data | |
47 | this.totalRecords = resultList.total | |
48 | }, | |
49 | ||
50 | err => this.notificationsService.error('Error', err.message) | |
51 | ) | |
52 | } | |
53 | } |