]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-library/my-follows/my-followers.component.ts
Add quick filter for followers
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-library / my-follows / my-followers.component.ts
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 { AdvancedInputFilter } from '@app/shared/shared-forms'
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
25 inputFilters: AdvancedInputFilter[]
26
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 }
38
39 this.auth.userInformationLoaded.subscribe(() => {
40 this.inputFilters = this.auth.getUser().videoChannels.map(c => {
41 return {
42 queryParams: { search: 'channel:' + c.name },
43 label: $localize`Followers of ${c.name}`
44 }
45 })
46 })
47 }
48
49 onNearOfBottom () {
50 // Last page
51 if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return
52
53 this.pagination.currentPage += 1
54 this.loadFollowers()
55 }
56
57 onSearch (search: string) {
58 this.search = search
59 this.loadFollowers(false)
60 }
61
62 isFollowingAccount (follow: ActorFollow) {
63 return follow.following.name === this.getUsername()
64 }
65
66 private loadFollowers (more = true) {
67 this.userSubscriptionService.listFollowers({
68 pagination: this.pagination,
69 nameWithHost: this.getUsername(),
70 search: this.search
71 }).subscribe({
72 next: res => {
73 this.follows = more
74 ? this.follows.concat(res.data)
75 : res.data
76 this.pagination.totalItems = res.total
77
78 this.onDataSubject.next(res.data)
79 },
80
81 error: err => this.notifier.error(err.message)
82 })
83 }
84
85 private getUsername () {
86 return this.auth.getUser().username
87 }
88 }