]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+about/about-follows/about-follows.component.ts
Change button
[github/Chocobozzz/PeerTube.git] / client / src / app / +about / about-follows / about-follows.component.ts
CommitLineData
a6dbbf03 1import { SortMeta } from 'primeng/api'
ad453580 2import { Subject } from 'rxjs'
67ed6552
C
3import { Component, OnInit } from '@angular/core'
4import { ComponentPagination, hasMoreItems, Notifier, RestService } from '@app/core'
5import { InstanceFollowService } from '@app/shared/shared-instance'
a6dbbf03
C
6
7@Component({
8 selector: 'my-about-follows',
9 templateUrl: './about-follows.component.html',
10 styleUrls: [ './about-follows.component.scss' ]
11})
12
13export class AboutFollowsComponent implements OnInit {
14 followers: string[] = []
15 followings: string[] = []
16
bd49f8e9
M
17 showMoreFollowers = false
18 showMoreFollowings = false
49c4dd7e 19
a6dbbf03
C
20 followersPagination: ComponentPagination = {
21 currentPage: 1,
ad453580 22 itemsPerPage: 20,
a6dbbf03
C
23 totalItems: null
24 }
25
26 followingsPagination: ComponentPagination = {
27 currentPage: 1,
ad453580 28 itemsPerPage: 20,
a6dbbf03
C
29 totalItems: null
30 }
31
32 sort: SortMeta = {
33 field: 'createdAt',
34 order: -1
35 }
36
ad453580
C
37 onDataSubject = new Subject<any[]>()
38
a6dbbf03
C
39 constructor (
40 private restService: RestService,
41 private notifier: Notifier,
67ed6552 42 private followService: InstanceFollowService
a6dbbf03
C
43 ) { }
44
45 ngOnInit () {
46 this.loadMoreFollowers()
47
48 this.loadMoreFollowings()
49 }
50
49c4dd7e 51 loadAllFollowings () {
bd49f8e9 52 while (hasMoreItems(this.followingsPagination)) {
49c4dd7e 53 this.followingsPagination.currentPage += 1
a6dbbf03 54
49c4dd7e
M
55 this.loadMoreFollowings()
56 }
a6dbbf03
C
57 }
58
49c4dd7e 59 loadAllFollowers () {
bd49f8e9 60 while (hasMoreItems(this.followersPagination)) {
49c4dd7e 61 this.followersPagination.currentPage += 1
bd49f8e9
M
62
63 this.loadMoreFollowers()
49c4dd7e 64 }
a6dbbf03
C
65 }
66
67 buildLink (host: string) {
68 return window.location.protocol + '//' + host
69 }
70
71 private loadMoreFollowers () {
72 const pagination = this.restService.componentPaginationToRestPagination(this.followersPagination)
73
b8f4167f 74 this.followService.getFollowers({ pagination: pagination, sort: this.sort, state: 'accepted' })
a6dbbf03
C
75 .subscribe(
76 resultList => {
77 const newFollowers = resultList.data.map(r => r.follower.host)
78 this.followers = this.followers.concat(newFollowers)
79
80 this.followersPagination.totalItems = resultList.total
ad453580
C
81
82 this.onDataSubject.next(newFollowers)
a6dbbf03
C
83 },
84
85 err => this.notifier.error(err.message)
86 )
87 }
88
89 private loadMoreFollowings () {
90 const pagination = this.restService.componentPaginationToRestPagination(this.followingsPagination)
91
b8f4167f 92 this.followService.getFollowing({ pagination, sort: this.sort, state: 'accepted' })
a6dbbf03
C
93 .subscribe(
94 resultList => {
95 const newFollowings = resultList.data.map(r => r.following.host)
96 this.followings = this.followings.concat(newFollowings)
97
98 this.followingsPagination.totalItems = resultList.total
ad453580
C
99
100 this.onDataSubject.next(newFollowings)
a6dbbf03
C
101 },
102
103 err => this.notifier.error(err.message)
104 )
105 }
106
107}