diff options
author | Chocobozzz <me@florianbigard.com> | 2021-10-19 09:44:43 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-10-20 09:25:44 +0200 |
commit | 4beda9e12adc7b1f3b178cecd6863ebf3cf431f1 (patch) | |
tree | 6244a10b286d66c6dcd7799aee630670d0493781 /client/src/app/+my-library/my-follows/my-followers.component.ts | |
parent | 9593a78ae1368a9ad8bb11044fce6fde2892701a (diff) | |
download | PeerTube-4beda9e12adc7b1f3b178cecd6863ebf3cf431f1.tar.gz PeerTube-4beda9e12adc7b1f3b178cecd6863ebf3cf431f1.tar.zst PeerTube-4beda9e12adc7b1f3b178cecd6863ebf3cf431f1.zip |
Add ability to view my followers
Diffstat (limited to 'client/src/app/+my-library/my-follows/my-followers.component.ts')
-rw-r--r-- | client/src/app/+my-library/my-follows/my-followers.component.ts | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/client/src/app/+my-library/my-follows/my-followers.component.ts b/client/src/app/+my-library/my-follows/my-followers.component.ts new file mode 100644 index 000000000..a7bbe6d99 --- /dev/null +++ b/client/src/app/+my-library/my-follows/my-followers.component.ts | |||
@@ -0,0 +1,76 @@ | |||
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' | ||
5 | import { UserSubscriptionService } from '@app/shared/shared-user-subscription' | ||
6 | import { ActorFollow } from '@shared/models' | ||
7 | |||
8 | @Component({ | ||
9 | templateUrl: './my-followers.component.html', | ||
10 | styleUrls: [ './my-followers.component.scss' ] | ||
11 | }) | ||
12 | export class MyFollowersComponent implements OnInit { | ||
13 | follows: ActorFollow[] = [] | ||
14 | |||
15 | pagination: ComponentPagination = { | ||
16 | currentPage: 1, | ||
17 | itemsPerPage: 10, | ||
18 | totalItems: null | ||
19 | } | ||
20 | |||
21 | onDataSubject = new Subject<any[]>() | ||
22 | search: string | ||
23 | |||
24 | constructor ( | ||
25 | private route: ActivatedRoute, | ||
26 | private auth: AuthService, | ||
27 | private userSubscriptionService: UserSubscriptionService, | ||
28 | private notifier: Notifier | ||
29 | ) {} | ||
30 | |||
31 | ngOnInit () { | ||
32 | if (this.route.snapshot.queryParams['search']) { | ||
33 | this.search = this.route.snapshot.queryParams['search'] | ||
34 | } | ||
35 | } | ||
36 | |||
37 | onNearOfBottom () { | ||
38 | // Last page | ||
39 | if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return | ||
40 | |||
41 | this.pagination.currentPage += 1 | ||
42 | this.loadFollowers() | ||
43 | } | ||
44 | |||
45 | onSearch (search: string) { | ||
46 | this.search = search | ||
47 | this.loadFollowers(false) | ||
48 | } | ||
49 | |||
50 | isFollowingAccount (follow: ActorFollow) { | ||
51 | return follow.following.name === this.getUsername() | ||
52 | } | ||
53 | |||
54 | private loadFollowers (more = true) { | ||
55 | this.userSubscriptionService.listFollowers({ | ||
56 | pagination: this.pagination, | ||
57 | nameWithHost: this.getUsername(), | ||
58 | search: this.search | ||
59 | }).subscribe({ | ||
60 | next: res => { | ||
61 | this.follows = more | ||
62 | ? this.follows.concat(res.data) | ||
63 | : res.data | ||
64 | this.pagination.totalItems = res.total | ||
65 | |||
66 | this.onDataSubject.next(res.data) | ||
67 | }, | ||
68 | |||
69 | error: err => this.notifier.error(err.message) | ||
70 | }) | ||
71 | } | ||
72 | |||
73 | private getUsername () { | ||
74 | return this.auth.getUser().username | ||
75 | } | ||
76 | } | ||