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