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