]>
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' |
51548b31 C |
8 | |
9 | @Component({ | |
c48e82b5 | 10 | templateUrl: './following-list.component.html', |
eeae8142 | 11 | styleUrls: [ './following-list.component.scss' ] |
51548b31 | 12 | }) |
ab998f7b | 13 | export class FollowingListComponent extends RestTable implements OnInit { |
4d029ef8 | 14 | @ViewChild('followModal') followModal: FollowModalComponent |
bb152476 | 15 | |
c48e82b5 | 16 | following: ActorFollow[] = [] |
51548b31 | 17 | totalRecords = 0 |
bb152476 | 18 | sort: SortMeta = { field: 'createdAt', order: -1 } |
51548b31 C |
19 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
20 | ||
073deef8 C |
21 | searchFilters: AdvancedInputFilter[] |
22 | ||
51548b31 | 23 | constructor ( |
f8b2c1b4 | 24 | private notifier: Notifier, |
7e9334c3 | 25 | private confirmService: ConfirmService, |
66357162 | 26 | private followService: InstanceFollowService |
9df52d66 | 27 | ) { |
51548b31 | 28 | super() |
073deef8 C |
29 | |
30 | this.searchFilters = this.followService.buildFollowsListFilters() | |
51548b31 C |
31 | } |
32 | ||
ab998f7b | 33 | ngOnInit () { |
24b9417c | 34 | this.initialize() |
ab998f7b C |
35 | } |
36 | ||
8e11a1b3 C |
37 | getIdentifier () { |
38 | return 'FollowingListComponent' | |
39 | } | |
40 | ||
4d029ef8 C |
41 | openFollowModal () { |
42 | this.followModal.openModal() | |
bb152476 RK |
43 | } |
44 | ||
4d029ef8 C |
45 | isInstanceFollowing (follow: ActorFollow) { |
46 | return follow.following.name === 'peertube' | |
bb152476 RK |
47 | } |
48 | ||
c48e82b5 | 49 | async removeFollowing (follow: ActorFollow) { |
b1d40cff | 50 | const res = await this.confirmService.confirm( |
66357162 C |
51 | $localize`Do you really want to unfollow ${follow.following.host}?`, |
52 | $localize`Unfollow` | |
b1d40cff | 53 | ) |
1f30a185 | 54 | if (res === false) return |
7e9334c3 | 55 | |
1378c0d3 C |
56 | this.followService.unfollow(follow) |
57 | .subscribe({ | |
58 | next: () => { | |
59 | this.notifier.success($localize`You are not following ${follow.following.host} anymore.`) | |
60 | this.reloadData() | |
61 | }, | |
7e9334c3 | 62 | |
1378c0d3 C |
63 | error: err => this.notifier.error(err.message) |
64 | }) | |
7e9334c3 C |
65 | } |
66 | ||
2e46eb97 | 67 | protected reloadData () { |
b8f4167f | 68 | this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search }) |
1378c0d3 C |
69 | .subscribe({ |
70 | next: resultList => { | |
51548b31 C |
71 | this.following = resultList.data |
72 | this.totalRecords = resultList.total | |
73 | }, | |
74 | ||
1378c0d3 C |
75 | error: err => this.notifier.error(err.message) |
76 | }) | |
51548b31 C |
77 | } |
78 | } |