]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/follows/following-list/following-list.component.ts
dd7629ead2b6036a1f36eb453226a4c0534aeb77
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / follows / following-list / following-list.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { SortMeta } from 'primeng/api'
4 import { ActorFollow } from '../../../../../../shared/models/actors/follow.model'
5 import { ConfirmService } from '../../../core/confirm/confirm.service'
6 import { RestPagination, RestTable } from '../../../shared'
7 import { FollowService } from '@app/shared/instance/follow.service'
8 import { I18n } from '@ngx-translate/i18n-polyfill'
9
10 @Component({
11 selector: 'my-followers-list',
12 templateUrl: './following-list.component.html',
13 styleUrls: [ './following-list.component.scss' ]
14 })
15 export class FollowingListComponent extends RestTable implements OnInit {
16 following: ActorFollow[] = []
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 notifier: Notifier,
24 private confirmService: ConfirmService,
25 private followService: FollowService,
26 private i18n: I18n
27 ) {
28 super()
29 }
30
31 ngOnInit () {
32 this.initialize()
33 }
34
35 getIdentifier () {
36 return 'FollowingListComponent'
37 }
38
39 async removeFollowing (follow: ActorFollow) {
40 const res = await this.confirmService.confirm(
41 this.i18n('Do you really want to unfollow {{host}}?', { host: follow.following.host }),
42 this.i18n('Unfollow')
43 )
44 if (res === false) return
45
46 this.followService.unfollow(follow).subscribe(
47 () => {
48 this.notifier.success(this.i18n('You are not following {{host}} anymore.', { host: follow.following.host }))
49 this.loadData()
50 },
51
52 err => this.notifier.error(err.message)
53 )
54 }
55
56 protected loadData () {
57 this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search })
58 .subscribe(
59 resultList => {
60 this.following = resultList.data
61 this.totalRecords = resultList.total
62 },
63
64 err => this.notifier.error(err.message)
65 )
66 }
67 }