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