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 followersPagination: ComponentPagination = {
23 followingsPagination: ComponentPagination = {
34 onDataSubject = new Subject<any[]>()
37 private restService: RestService,
38 private notifier: Notifier,
39 private followService: InstanceFollowService
43 this.loadMoreFollowers()
45 this.loadMoreFollowings()
49 this.onNearOfFollowersBottom()
51 this.onNearOfFollowingsBottom()
54 onNearOfFollowersBottom () {
55 if (!hasMoreItems(this.followersPagination)) return
57 this.followersPagination.currentPage += 1
58 this.loadMoreFollowers()
61 onNearOfFollowingsBottom () {
62 if (!hasMoreItems(this.followingsPagination)) return
64 this.followingsPagination.currentPage += 1
65 this.loadMoreFollowings()
68 buildLink (host: string) {
69 return window.location.protocol + '//' + host
72 private loadMoreFollowers () {
73 const pagination = this.restService.componentPaginationToRestPagination(this.followersPagination)
75 this.followService.getFollowers({ pagination: pagination, sort: this.sort, state: 'accepted' })
78 const newFollowers = resultList.data.map(r => r.follower.host)
79 this.followers = this.followers.concat(newFollowers)
81 this.followersPagination.totalItems = resultList.total
83 this.onDataSubject.next(newFollowers)
86 err => this.notifier.error(err.message)
90 private loadMoreFollowings () {
91 const pagination = this.restService.componentPaginationToRestPagination(this.followingsPagination)
93 this.followService.getFollowing({ pagination, sort: this.sort, state: 'accepted' })
96 const newFollowings = resultList.data.map(r => r.following.host)
97 this.followings = this.followings.concat(newFollowings)
99 this.followingsPagination.totalItems = resultList.total
101 this.onDataSubject.next(newFollowings)
104 err => this.notifier.error(err.message)