1 import { SortMeta } from 'primeng/api'
2 import { Subject } from 'rxjs'
3 import { Component, OnInit } from '@angular/core'
4 import { ComponentPagination, hasMoreItems, Notifier, RestService } from '@app/core'
5 import { InstanceFollowService } from '@app/shared/shared-instance'
8 selector: 'my-about-follows',
9 templateUrl: './about-follows.component.html',
10 styleUrls: [ './about-follows.component.scss' ]
13 export class AboutFollowsComponent implements OnInit {
14 followers: string[] = []
15 followings: string[] = []
16 moreFollowers: string[] = []
17 moreFollowings: string[] = []
19 showMoreFollowers = false
20 showMoreFollowings = false
22 followersPagination: ComponentPagination = {
28 followingsPagination: ComponentPagination = {
39 onDataSubject = new Subject<any[]>()
42 private restService: RestService,
43 private notifier: Notifier,
44 private followService: InstanceFollowService
48 this.loadMoreFollowers()
50 this.loadMoreFollowings()
53 loadAllFollowings () {
54 while (hasMoreItems(this.followingsPagination)) {
55 this.followingsPagination.currentPage += 1
57 this.loadMoreFollowings()
62 while (hasMoreItems(this.followersPagination)) {
63 this.followersPagination.currentPage += 1
65 this.loadMoreFollowers()
69 buildLink (host: string) {
70 return window.location.protocol + '//' + host
73 private loadMoreFollowers () {
74 const pagination = this.restService.componentPaginationToRestPagination(this.followersPagination)
76 this.followService.getFollowers({ pagination: pagination, sort: this.sort, state: 'accepted' })
79 const newFollowers = resultList.data.map(r => r.follower.host)
80 if (this.followers.length === 0) this.followers = this.followers.concat(newFollowers)
82 else this.moreFollowers = this.moreFollowers.concat(newFollowers)
84 this.followersPagination.totalItems = resultList.total
86 this.onDataSubject.next(newFollowers)
89 err => this.notifier.error(err.message)
93 private loadMoreFollowings () {
94 const pagination = this.restService.componentPaginationToRestPagination(this.followingsPagination)
96 this.followService.getFollowing({ pagination, sort: this.sort, state: 'accepted' })
99 const newFollowings = resultList.data.map(r => r.following.host)
100 if (this.followings.length === 0) this.followings = this.followings.concat(newFollowings)
102 else this.moreFollowings = this.moreFollowings.concat(newFollowings)
104 this.followingsPagination.totalItems = resultList.total
106 this.onDataSubject.next(newFollowings)
109 err => this.notifier.error(err.message)