]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+about/about-follows/about-follows.component.ts
fix merge conflicts
[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[] = []
2ce94945
M
16 moreFollowers: string[] = []
17 moreFollowings: string[] = []
a6dbbf03 18
bd49f8e9
M
19 showMoreFollowers = false
20 showMoreFollowings = false
49c4dd7e 21
a6dbbf03
C
22 followersPagination: ComponentPagination = {
23 currentPage: 1,
ad453580 24 itemsPerPage: 20,
a6dbbf03
C
25 totalItems: null
26 }
27
28 followingsPagination: ComponentPagination = {
29 currentPage: 1,
ad453580 30 itemsPerPage: 20,
a6dbbf03
C
31 totalItems: null
32 }
33
34 sort: SortMeta = {
35 field: 'createdAt',
36 order: -1
37 }
38
ad453580
C
39 onDataSubject = new Subject<any[]>()
40
a6dbbf03
C
41 constructor (
42 private restService: RestService,
43 private notifier: Notifier,
67ed6552 44 private followService: InstanceFollowService
a6dbbf03
C
45 ) { }
46
47 ngOnInit () {
48 this.loadMoreFollowers()
49
50 this.loadMoreFollowings()
51 }
52
49c4dd7e 53 loadAllFollowings () {
bd49f8e9 54 while (hasMoreItems(this.followingsPagination)) {
49c4dd7e 55 this.followingsPagination.currentPage += 1
a6dbbf03 56
49c4dd7e
M
57 this.loadMoreFollowings()
58 }
a6dbbf03
C
59 }
60
49c4dd7e 61 loadAllFollowers () {
bd49f8e9 62 while (hasMoreItems(this.followersPagination)) {
49c4dd7e 63 this.followersPagination.currentPage += 1
bd49f8e9
M
64
65 this.loadMoreFollowers()
49c4dd7e 66 }
a6dbbf03
C
67 }
68
69 buildLink (host: string) {
70 return window.location.protocol + '//' + host
71 }
72
73 private loadMoreFollowers () {
74 const pagination = this.restService.componentPaginationToRestPagination(this.followersPagination)
75
b8f4167f 76 this.followService.getFollowers({ pagination: pagination, sort: this.sort, state: 'accepted' })
a6dbbf03
C
77 .subscribe(
78 resultList => {
79 const newFollowers = resultList.data.map(r => r.follower.host)
2ce94945
M
80 if (this.followers.length === 0) this.followers = this.followers.concat(newFollowers)
81
82 else this.moreFollowers = this.moreFollowers.concat(newFollowers)
a6dbbf03
C
83
84 this.followersPagination.totalItems = resultList.total
ad453580
C
85
86 this.onDataSubject.next(newFollowers)
a6dbbf03
C
87 },
88
89 err => this.notifier.error(err.message)
90 )
91 }
92
93 private loadMoreFollowings () {
94 const pagination = this.restService.componentPaginationToRestPagination(this.followingsPagination)
95
b8f4167f 96 this.followService.getFollowing({ pagination, sort: this.sort, state: 'accepted' })
a6dbbf03
C
97 .subscribe(
98 resultList => {
99 const newFollowings = resultList.data.map(r => r.following.host)
92f62f10 100 if (this.followings.length === 0) this.followings = this.followings.concat(newFollowings)
2ce94945
M
101
102 else this.moreFollowings = this.moreFollowings.concat(newFollowings)
a6dbbf03
C
103
104 this.followingsPagination.totalItems = resultList.total
ad453580
C
105
106 this.onDataSubject.next(newFollowings)
a6dbbf03
C
107 },
108
109 err => this.notifier.error(err.message)
110 )
111 }
112
113}