PeerTube/client/src/app/+admin/follows/following-list/following-list.component.ts

104 lines
3.1 KiB
TypeScript
Raw Normal View History

2019-07-25 10:44:21 +02:00
import { SortMeta } from 'primeng/api'
2020-06-23 14:10:17 +02:00
import { Component, OnInit, ViewChild } from '@angular/core'
import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
import { AdvancedInputFilter } from '@app/shared/shared-forms'
2020-06-23 14:10:17 +02:00
import { InstanceFollowService } from '@app/shared/shared-instance'
import { ActorFollow } from '@peertube/peertube-models'
import { FollowModalComponent } from './follow-modal.component'
2022-07-27 13:44:40 +02:00
import { DropdownAction } from '@app/shared/shared-main'
2023-06-06 14:32:47 +02:00
import { formatICU } from '@app/helpers'
@Component({
2018-09-11 16:27:07 +02:00
templateUrl: './following-list.component.html',
2021-10-29 11:33:28 +02:00
styleUrls: [ './following-list.component.scss' ]
})
export class FollowingListComponent extends RestTable <ActorFollow> implements OnInit {
@ViewChild('followModal') followModal: FollowModalComponent
2018-09-11 16:27:07 +02:00
following: ActorFollow[] = []
totalRecords = 0
sort: SortMeta = { field: 'createdAt', order: -1 }
pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
2022-07-27 13:44:40 +02:00
searchFilters: AdvancedInputFilter[] = []
bulkActions: DropdownAction<ActorFollow[]>[] = []
constructor (
private notifier: Notifier,
2017-11-20 11:19:23 +01:00
private confirmService: ConfirmService,
private followService: InstanceFollowService
2021-08-17 14:42:53 +02:00
) {
super()
}
2018-02-23 14:36:16 +01:00
ngOnInit () {
2018-10-08 15:51:38 +02:00
this.initialize()
2022-07-27 13:44:40 +02:00
this.searchFilters = this.followService.buildFollowsListFilters()
this.bulkActions = [
2022-07-27 13:44:40 +02:00
{
label: $localize`Delete`,
handler: follows => this.removeFollowing(follows)
}
]
2018-02-23 14:36:16 +01:00
}
2020-04-08 10:49:26 +02:00
getIdentifier () {
return 'FollowingListComponent'
}
openFollowModal () {
this.followModal.openModal()
}
isInstanceFollowing (follow: ActorFollow) {
return follow.following.name === 'peertube'
}
2022-07-27 13:44:40 +02:00
buildFollowingName (follow: ActorFollow) {
return follow.following.name + '@' + follow.following.host
}
async removeFollowing (follows: ActorFollow[]) {
2023-01-20 15:06:08 +01:00
const icuParams = { count: follows.length, entryName: this.buildFollowingName(follows[0]) }
2023-06-06 14:32:47 +02:00
const message = formatICU(
$localize`Do you really want to unfollow {count, plural, =1 {{entryName}?} other {{count} entries?}}`,
icuParams
2018-06-04 16:21:17 +02:00
)
2022-07-27 13:44:40 +02:00
const res = await this.confirmService.confirm(message, $localize`Unfollow`)
if (res === false) return
2017-11-20 11:19:23 +01:00
2022-07-27 13:44:40 +02:00
this.followService.unfollow(follows)
2021-08-17 11:27:47 +02:00
.subscribe({
next: () => {
2022-07-27 13:44:40 +02:00
// eslint-disable-next-line max-len
2023-06-06 14:32:47 +02:00
const message = formatICU(
$localize`You are not following {count, plural, =1 {{entryName} anymore.} other {these {count} entries anymore.}}`,
icuParams
2022-07-27 13:44:40 +02:00
)
this.notifier.success(message)
2021-08-17 11:27:47 +02:00
this.reloadData()
},
2017-11-20 11:19:23 +01:00
2021-08-17 11:27:47 +02:00
error: err => this.notifier.error(err.message)
})
2017-11-20 11:19:23 +01:00
}
2023-01-20 15:06:08 +01:00
protected reloadDataInternal () {
this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search })
2021-08-17 11:27:47 +02:00
.subscribe({
next: resultList => {
this.following = resultList.data
this.totalRecords = resultList.total
},
2021-08-17 11:27:47 +02:00
error: err => this.notifier.error(err.message)
})
}
}