]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/follows/following-list/following-list.component.ts
Add short description in config
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / follows / following-list / following-list.component.ts
CommitLineData
ab998f7b 1import { Component, OnInit } from '@angular/core'
51548b31
C
2import { NotificationsService } from 'angular2-notifications'
3import { SortMeta } from 'primeng/primeng'
50d6de9c 4import { AccountFollow } from '../../../../../../shared/models/actors/follow.model'
7e9334c3 5import { ConfirmService } from '../../../core/confirm/confirm.service'
60862425 6import { RestPagination, RestTable } from '../../../shared'
51548b31
C
7import { FollowService } from '../shared'
8
9@Component({
10 selector: 'my-followers-list',
11 templateUrl: './following-list.component.html'
12})
ab998f7b 13export class FollowingListComponent extends RestTable implements OnInit {
60862425 14 following: AccountFollow[] = []
51548b31
C
15 totalRecords = 0
16 rowsPerPage = 10
17 sort: SortMeta = { field: 'createdAt', order: 1 }
18 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
19
20 constructor (
21 private notificationsService: NotificationsService,
7e9334c3 22 private confirmService: ConfirmService,
51548b31
C
23 private followService: FollowService
24 ) {
25 super()
26 }
27
ab998f7b
C
28 ngOnInit () {
29 this.loadSort()
30 }
31
1f30a185
C
32 async removeFollowing (follow: AccountFollow) {
33 const res = await this.confirmService.confirm(`Do you really want to unfollow ${follow.following.host}?`, 'Unfollow')
34 if (res === false) return
7e9334c3 35
1f30a185
C
36 this.followService.unfollow(follow).subscribe(
37 () => {
38 this.notificationsService.success('Success', `You are not following ${follow.following.host} anymore.`)
39 this.loadData()
40 },
7e9334c3 41
1f30a185 42 err => this.notificationsService.error('Error', err.message)
7e9334c3
C
43 )
44 }
45
51548b31
C
46 protected loadData () {
47 this.followService.getFollowing(this.pagination, this.sort)
48 .subscribe(
49 resultList => {
50 this.following = resultList.data
51 this.totalRecords = resultList.total
52 },
53
54 err => this.notificationsService.error('Error', err.message)
55 )
56 }
57}