]>
Commit | Line | Data |
---|---|---|
4beda9e1 C |
1 | import { Subject } from 'rxjs' |
2 | import { Component, OnInit } from '@angular/core' | |
3 | import { ActivatedRoute } from '@angular/router' | |
4 | import { AuthService, ComponentPagination, Notifier } from '@app/core' | |
7e76cc38 | 5 | import { AdvancedInputFilter } from '@app/shared/shared-forms' |
4beda9e1 C |
6 | import { UserSubscriptionService } from '@app/shared/shared-user-subscription' |
7 | import { ActorFollow } from '@shared/models' | |
8 | ||
9 | @Component({ | |
10 | templateUrl: './my-followers.component.html', | |
11 | styleUrls: [ './my-followers.component.scss' ] | |
12 | }) | |
13 | export class MyFollowersComponent implements OnInit { | |
14 | follows: ActorFollow[] = [] | |
15 | ||
16 | pagination: ComponentPagination = { | |
17 | currentPage: 1, | |
18 | itemsPerPage: 10, | |
19 | totalItems: null | |
20 | } | |
21 | ||
22 | onDataSubject = new Subject<any[]>() | |
23 | search: string | |
24 | ||
7e76cc38 C |
25 | inputFilters: AdvancedInputFilter[] |
26 | ||
4beda9e1 C |
27 | constructor ( |
28 | private route: ActivatedRoute, | |
29 | private auth: AuthService, | |
30 | private userSubscriptionService: UserSubscriptionService, | |
31 | private notifier: Notifier | |
32 | ) {} | |
33 | ||
34 | ngOnInit () { | |
35 | if (this.route.snapshot.queryParams['search']) { | |
36 | this.search = this.route.snapshot.queryParams['search'] | |
37 | } | |
7e76cc38 C |
38 | |
39 | this.auth.userInformationLoaded.subscribe(() => { | |
978c87e7 | 40 | const channelFilters = this.auth.getUser().videoChannels.map(c => { |
7e76cc38 | 41 | return { |
dd6d2a7c | 42 | value: 'channel:' + c.name, |
978c87e7 | 43 | label: c.name |
7e76cc38 C |
44 | } |
45 | }) | |
978c87e7 C |
46 | |
47 | this.inputFilters = [ | |
48 | { | |
49 | title: $localize`Channel filters`, | |
50 | children: channelFilters | |
51 | } | |
52 | ] | |
7e76cc38 | 53 | }) |
4beda9e1 C |
54 | } |
55 | ||
56 | onNearOfBottom () { | |
57 | // Last page | |
58 | if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return | |
59 | ||
60 | this.pagination.currentPage += 1 | |
61 | this.loadFollowers() | |
62 | } | |
63 | ||
64 | onSearch (search: string) { | |
65 | this.search = search | |
66 | this.loadFollowers(false) | |
67 | } | |
68 | ||
69 | isFollowingAccount (follow: ActorFollow) { | |
70 | return follow.following.name === this.getUsername() | |
71 | } | |
72 | ||
73 | private loadFollowers (more = true) { | |
74 | this.userSubscriptionService.listFollowers({ | |
75 | pagination: this.pagination, | |
76 | nameWithHost: this.getUsername(), | |
77 | search: this.search | |
78 | }).subscribe({ | |
79 | next: res => { | |
80 | this.follows = more | |
81 | ? this.follows.concat(res.data) | |
82 | : res.data | |
83 | this.pagination.totalItems = res.total | |
84 | ||
85 | this.onDataSubject.next(res.data) | |
86 | }, | |
87 | ||
88 | error: err => this.notifier.error(err.message) | |
89 | }) | |
90 | } | |
91 | ||
92 | private getUsername () { | |
93 | return this.auth.getUser().username | |
94 | } | |
95 | } |