]>
Commit | Line | Data |
---|---|---|
ab998f7b | 1 | import { Component, OnInit } 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 | 7 | import { FollowService } from '../shared' |
b1d40cff | 8 | import { I18n } from '@ngx-translate/i18n-polyfill' |
51548b31 C |
9 | |
10 | @Component({ | |
11 | selector: 'my-followers-list', | |
12 | templateUrl: './following-list.component.html' | |
13 | }) | |
ab998f7b | 14 | export class FollowingListComponent extends RestTable implements OnInit { |
60862425 | 15 | following: AccountFollow[] = [] |
51548b31 C |
16 | totalRecords = 0 |
17 | rowsPerPage = 10 | |
18 | sort: SortMeta = { field: 'createdAt', order: 1 } | |
19 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
20 | ||
21 | constructor ( | |
22 | private notificationsService: NotificationsService, | |
7e9334c3 | 23 | private confirmService: ConfirmService, |
b1d40cff C |
24 | private followService: FollowService, |
25 | private i18n: I18n | |
51548b31 C |
26 | ) { |
27 | super() | |
28 | } | |
29 | ||
ab998f7b C |
30 | ngOnInit () { |
31 | this.loadSort() | |
32 | } | |
33 | ||
1f30a185 | 34 | async removeFollowing (follow: AccountFollow) { |
b1d40cff | 35 | const res = await this.confirmService.confirm( |
25acef90 | 36 | this.i18n('Do you really want to unfollow {{host}}?', { host: follow.following.host }), |
b1d40cff C |
37 | this.i18n('Unfollow') |
38 | ) | |
1f30a185 | 39 | if (res === false) return |
7e9334c3 | 40 | |
1f30a185 C |
41 | this.followService.unfollow(follow).subscribe( |
42 | () => { | |
b1d40cff C |
43 | this.notificationsService.success( |
44 | this.i18n('Success'), | |
25acef90 | 45 | this.i18n('You are not following {{host}} anymore.', { host: follow.following.host }) |
b1d40cff | 46 | ) |
1f30a185 C |
47 | this.loadData() |
48 | }, | |
7e9334c3 | 49 | |
b1d40cff | 50 | err => this.notificationsService.error(this.i18n('Error'), err.message) |
7e9334c3 C |
51 | ) |
52 | } | |
53 | ||
51548b31 C |
54 | protected loadData () { |
55 | this.followService.getFollowing(this.pagination, this.sort) | |
56 | .subscribe( | |
57 | resultList => { | |
58 | this.following = resultList.data | |
59 | this.totalRecords = resultList.total | |
60 | }, | |
61 | ||
b1d40cff | 62 | err => this.notificationsService.error(this.i18n('Error'), err.message) |
51548b31 C |
63 | ) |
64 | } | |
65 | } |