1 import { SortMeta } from 'primeng/api'
2 import { Component, OnInit, ViewChild } from '@angular/core'
3 import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
4 import { AdvancedInputFilter } from '@app/shared/shared-forms'
5 import { InstanceFollowService } from '@app/shared/shared-instance'
6 import { ActorFollow } from '@shared/models'
7 import { FollowModalComponent } from './follow-modal.component'
8 import { DropdownAction } from '@app/shared/shared-main'
9 import { prepareIcu } from '@app/helpers'
12 templateUrl: './following-list.component.html',
13 styleUrls: [ './following-list.component.scss' ]
15 export class FollowingListComponent extends RestTable implements OnInit {
16 @ViewChild('followModal') followModal: FollowModalComponent
18 following: ActorFollow[] = []
20 sort: SortMeta = { field: 'createdAt', order: -1 }
21 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
23 searchFilters: AdvancedInputFilter[] = []
25 selectedFollows: ActorFollow[] = []
26 bulkFollowsActions: DropdownAction<ActorFollow[]>[] = []
29 private notifier: Notifier,
30 private confirmService: ConfirmService,
31 private followService: InstanceFollowService
39 this.searchFilters = this.followService.buildFollowsListFilters()
41 this.bulkFollowsActions = [
43 label: $localize`Delete`,
44 handler: follows => this.removeFollowing(follows)
50 return 'FollowingListComponent'
54 this.followModal.openModal()
57 isInstanceFollowing (follow: ActorFollow) {
58 return follow.following.name === 'peertube'
61 isInSelectionMode () {
62 return this.selectedFollows.length !== 0
65 buildFollowingName (follow: ActorFollow) {
66 return follow.following.name + '@' + follow.following.host
69 async removeFollowing (follows: ActorFollow[]) {
70 const message = prepareIcu($localize`Do you really want to unfollow {count, plural, =1 {{entryName}?} other {{count} entries?}}`)(
71 { count: follows.length, entryName: this.buildFollowingName(follows[0]) },
72 $localize`Do you really want to unfollow these entries?`
75 const res = await this.confirmService.confirm(message, $localize`Unfollow`)
76 if (res === false) return
78 this.followService.unfollow(follows)
81 // eslint-disable-next-line max-len
82 const message = prepareIcu($localize`You are not following {count, plural, =1 {{entryName} anymore.} other {these {count} entries anymore.}}`)(
83 { count: follows.length, entryName: this.buildFollowingName(follows[0]) },
84 $localize`You are not following them anymore.`
87 this.notifier.success(message)
91 error: err => this.notifier.error(err.message)
95 protected reloadData () {
96 this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search })
99 this.following = resultList.data
100 this.totalRecords = resultList.total
103 error: err => this.notifier.error(err.message)