]>
Commit | Line | Data |
---|---|---|
41b15c89 | 1 | import { SortMeta } from 'primeng/api' |
67ed6552 C |
2 | import { Component, OnInit, ViewChild } from '@angular/core' |
3 | import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core' | |
073deef8 | 4 | import { AdvancedInputFilter } from '@app/shared/shared-forms' |
67ed6552 | 5 | import { InstanceFollowService } from '@app/shared/shared-instance' |
67ed6552 | 6 | import { ActorFollow } from '@shared/models' |
4d029ef8 | 7 | import { FollowModalComponent } from './follow-modal.component' |
e3d6c643 C |
8 | import { DropdownAction } from '@app/shared/shared-main' |
9 | import { prepareIcu } from '@app/helpers' | |
51548b31 C |
10 | |
11 | @Component({ | |
c48e82b5 | 12 | templateUrl: './following-list.component.html', |
eeae8142 | 13 | styleUrls: [ './following-list.component.scss' ] |
51548b31 | 14 | }) |
cd940f40 | 15 | export class FollowingListComponent extends RestTable <ActorFollow> implements OnInit { |
4d029ef8 | 16 | @ViewChild('followModal') followModal: FollowModalComponent |
bb152476 | 17 | |
c48e82b5 | 18 | following: ActorFollow[] = [] |
51548b31 | 19 | totalRecords = 0 |
bb152476 | 20 | sort: SortMeta = { field: 'createdAt', order: -1 } |
51548b31 C |
21 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
22 | ||
e3d6c643 C |
23 | searchFilters: AdvancedInputFilter[] = [] |
24 | ||
cd940f40 | 25 | bulkActions: DropdownAction<ActorFollow[]>[] = [] |
073deef8 | 26 | |
51548b31 | 27 | constructor ( |
f8b2c1b4 | 28 | private notifier: Notifier, |
7e9334c3 | 29 | private confirmService: ConfirmService, |
66357162 | 30 | private followService: InstanceFollowService |
9df52d66 | 31 | ) { |
51548b31 C |
32 | super() |
33 | } | |
34 | ||
ab998f7b | 35 | ngOnInit () { |
24b9417c | 36 | this.initialize() |
e3d6c643 C |
37 | |
38 | this.searchFilters = this.followService.buildFollowsListFilters() | |
39 | ||
cd940f40 | 40 | this.bulkActions = [ |
e3d6c643 C |
41 | { |
42 | label: $localize`Delete`, | |
43 | handler: follows => this.removeFollowing(follows) | |
44 | } | |
45 | ] | |
ab998f7b C |
46 | } |
47 | ||
8e11a1b3 C |
48 | getIdentifier () { |
49 | return 'FollowingListComponent' | |
50 | } | |
51 | ||
4d029ef8 C |
52 | openFollowModal () { |
53 | this.followModal.openModal() | |
bb152476 RK |
54 | } |
55 | ||
4d029ef8 C |
56 | isInstanceFollowing (follow: ActorFollow) { |
57 | return follow.following.name === 'peertube' | |
bb152476 RK |
58 | } |
59 | ||
e3d6c643 C |
60 | buildFollowingName (follow: ActorFollow) { |
61 | return follow.following.name + '@' + follow.following.host | |
62 | } | |
63 | ||
64 | async removeFollowing (follows: ActorFollow[]) { | |
e854d57b C |
65 | const icuParams = { count: follows.length, entryName: this.buildFollowingName(follows[0]) } |
66 | ||
e3d6c643 | 67 | const message = prepareIcu($localize`Do you really want to unfollow {count, plural, =1 {{entryName}?} other {{count} entries?}}`)( |
e854d57b | 68 | icuParams, |
e3d6c643 | 69 | $localize`Do you really want to unfollow these entries?` |
b1d40cff | 70 | ) |
e3d6c643 C |
71 | |
72 | const res = await this.confirmService.confirm(message, $localize`Unfollow`) | |
1f30a185 | 73 | if (res === false) return |
7e9334c3 | 74 | |
e3d6c643 | 75 | this.followService.unfollow(follows) |
1378c0d3 C |
76 | .subscribe({ |
77 | next: () => { | |
e3d6c643 C |
78 | // eslint-disable-next-line max-len |
79 | const message = prepareIcu($localize`You are not following {count, plural, =1 {{entryName} anymore.} other {these {count} entries anymore.}}`)( | |
e854d57b | 80 | icuParams, |
e3d6c643 C |
81 | $localize`You are not following them anymore.` |
82 | ) | |
83 | ||
84 | this.notifier.success(message) | |
1378c0d3 C |
85 | this.reloadData() |
86 | }, | |
7e9334c3 | 87 | |
1378c0d3 C |
88 | error: err => this.notifier.error(err.message) |
89 | }) | |
7e9334c3 C |
90 | } |
91 | ||
e854d57b | 92 | protected reloadDataInternal () { |
b8f4167f | 93 | this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search }) |
1378c0d3 C |
94 | .subscribe({ |
95 | next: resultList => { | |
51548b31 C |
96 | this.following = resultList.data |
97 | this.totalRecords = resultList.total | |
98 | }, | |
99 | ||
1378c0d3 C |
100 | error: err => this.notifier.error(err.message) |
101 | }) | |
51548b31 C |
102 | } |
103 | } |