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