]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/follows/following-list/following-list.component.ts
Fix invalid margin when loader is not displayed
[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'
67ed6552 5import { ActorFollow } from '@shared/models'
4d029ef8 6import { FollowModalComponent } from './follow-modal.component'
51548b31
C
7
8@Component({
c48e82b5 9 templateUrl: './following-list.component.html',
eeae8142 10 styleUrls: [ './following-list.component.scss' ]
51548b31 11})
ab998f7b 12export class FollowingListComponent extends RestTable implements OnInit {
4d029ef8 13 @ViewChild('followModal') followModal: FollowModalComponent
bb152476 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 23 private followService: InstanceFollowService
9df52d66 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
4d029ef8
C
36 openFollowModal () {
37 this.followModal.openModal()
bb152476
RK
38 }
39
4d029ef8
C
40 isInstanceFollowing (follow: ActorFollow) {
41 return follow.following.name === 'peertube'
bb152476
RK
42 }
43
c48e82b5 44 async removeFollowing (follow: ActorFollow) {
b1d40cff 45 const res = await this.confirmService.confirm(
66357162
C
46 $localize`Do you really want to unfollow ${follow.following.host}?`,
47 $localize`Unfollow`
b1d40cff 48 )
1f30a185 49 if (res === false) return
7e9334c3 50
1378c0d3
C
51 this.followService.unfollow(follow)
52 .subscribe({
53 next: () => {
54 this.notifier.success($localize`You are not following ${follow.following.host} anymore.`)
55 this.reloadData()
56 },
7e9334c3 57
1378c0d3
C
58 error: err => this.notifier.error(err.message)
59 })
7e9334c3
C
60 }
61
2e46eb97 62 protected reloadData () {
b8f4167f 63 this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search })
1378c0d3
C
64 .subscribe({
65 next: resultList => {
51548b31
C
66 this.following = resultList.data
67 this.totalRecords = resultList.total
68 },
69
1378c0d3
C
70 error: err => this.notifier.error(err.message)
71 })
51548b31
C
72 }
73}