]>
Commit | Line | Data |
---|---|---|
bb152476 | 1 | import { Component, OnInit, ViewChild } from '@angular/core' |
f8b2c1b4 | 2 | import { Notifier } from '@app/core' |
41b15c89 | 3 | import { SortMeta } from 'primeng/api' |
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' |
a6dbbf03 | 7 | import { FollowService } from '@app/shared/instance/follow.service' |
b1d40cff | 8 | import { I18n } from '@ngx-translate/i18n-polyfill' |
bb152476 | 9 | import { BatchDomainsModalComponent } from '@app/+admin/config/shared/batch-domains-modal.component' |
51548b31 C |
10 | |
11 | @Component({ | |
12 | selector: 'my-followers-list', | |
c48e82b5 | 13 | templateUrl: './following-list.component.html', |
d3840613 | 14 | styleUrls: [ '../follows.component.scss', './following-list.component.scss' ] |
51548b31 | 15 | }) |
ab998f7b | 16 | export class FollowingListComponent extends RestTable implements OnInit { |
bb152476 RK |
17 | @ViewChild('batchDomainsModal') batchDomainsModal: BatchDomainsModalComponent |
18 | ||
c48e82b5 | 19 | following: ActorFollow[] = [] |
51548b31 C |
20 | totalRecords = 0 |
21 | rowsPerPage = 10 | |
bb152476 | 22 | sort: SortMeta = { field: 'createdAt', order: -1 } |
51548b31 C |
23 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
24 | ||
25 | constructor ( | |
f8b2c1b4 | 26 | private notifier: Notifier, |
7e9334c3 | 27 | private confirmService: ConfirmService, |
b1d40cff C |
28 | private followService: FollowService, |
29 | private i18n: I18n | |
51548b31 C |
30 | ) { |
31 | super() | |
32 | } | |
33 | ||
ab998f7b | 34 | ngOnInit () { |
24b9417c | 35 | this.initialize() |
ab998f7b C |
36 | } |
37 | ||
8e11a1b3 C |
38 | getIdentifier () { |
39 | return 'FollowingListComponent' | |
40 | } | |
41 | ||
bb152476 RK |
42 | addDomainsToFollow () { |
43 | this.batchDomainsModal.openModal() | |
44 | } | |
45 | ||
46 | async addFollowing (hosts: string[]) { | |
47 | this.followService.follow(hosts).subscribe( | |
48 | () => { | |
49 | this.notifier.success(this.i18n('Follow request(s) sent!')) | |
50 | this.loadData() | |
51 | }, | |
52 | ||
53 | err => this.notifier.error(err.message) | |
54 | ) | |
55 | } | |
56 | ||
c48e82b5 | 57 | async removeFollowing (follow: ActorFollow) { |
b1d40cff | 58 | const res = await this.confirmService.confirm( |
25acef90 | 59 | this.i18n('Do you really want to unfollow {{host}}?', { host: follow.following.host }), |
b1d40cff C |
60 | this.i18n('Unfollow') |
61 | ) | |
1f30a185 | 62 | if (res === false) return |
7e9334c3 | 63 | |
1f30a185 C |
64 | this.followService.unfollow(follow).subscribe( |
65 | () => { | |
f8b2c1b4 | 66 | this.notifier.success(this.i18n('You are not following {{host}} anymore.', { host: follow.following.host })) |
1f30a185 C |
67 | this.loadData() |
68 | }, | |
7e9334c3 | 69 | |
f8b2c1b4 | 70 | err => this.notifier.error(err.message) |
7e9334c3 C |
71 | ) |
72 | } | |
73 | ||
51548b31 | 74 | protected loadData () { |
b8f4167f | 75 | this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search }) |
51548b31 C |
76 | .subscribe( |
77 | resultList => { | |
78 | this.following = resultList.data | |
79 | this.totalRecords = resultList.total | |
80 | }, | |
81 | ||
f8b2c1b4 | 82 | err => this.notifier.error(err.message) |
51548b31 C |
83 | ) |
84 | } | |
85 | } |