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