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[] = []
17 showMoreFollowers = false
18 showMoreFollowings = false
20 followersPagination: ComponentPagination = {
26 followingsPagination: ComponentPagination = {
37 onDataSubject = new Subject<any[]>()
40 private restService: RestService,
41 private notifier: Notifier,
42 private followService: InstanceFollowService
46 this.loadMoreFollowers()
48 this.loadMoreFollowings()
51 loadAllFollowings () {
52 while (hasMoreItems(this.followingsPagination)) {
53 this.followingsPagination.currentPage += 1
55 this.loadMoreFollowings()
60 while (hasMoreItems(this.followersPagination)) {
61 this.followersPagination.currentPage += 1
63 this.loadMoreFollowers()
67 buildLink (host: string) {
68 return window.location.protocol + '//' + host
71 private loadMoreFollowers () {
72 const pagination = this.restService.componentPaginationToRestPagination(this.followersPagination)
74 this.followService.getFollowers({ pagination: pagination, sort: this.sort, state: 'accepted' })
77 const newFollowers = resultList.data.map(r => r.follower.host)
78 this.followers = this.followers.concat(newFollowers)
80 this.followersPagination.totalItems = resultList.total
82 this.onDataSubject.next(newFollowers)
85 err => this.notifier.error(err.message)
89 private loadMoreFollowings () {
90 const pagination = this.restService.componentPaginationToRestPagination(this.followingsPagination)
92 this.followService.getFollowing({ pagination, sort: this.sort, state: 'accepted' })
95 const newFollowings = resultList.data.map(r => r.following.host)
96 this.followings = this.followings.concat(newFollowings)
98 this.followingsPagination.totalItems = resultList.total
100 this.onDataSubject.next(newFollowings)
103 err => this.notifier.error(err.message)