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