1 import { Component, OnInit } from '@angular/core'
2 import { FollowService } from '@app/shared/instance/follow.service'
3 import { ComponentPagination, hasMoreItems } from '@app/shared/rest/component-pagination.model'
4 import { Notifier } from '@app/core'
5 import { RestService } from '@app/shared'
6 import { SortMeta } from 'primeng/api'
7 import { Subject } from 'rxjs'
10 selector: 'my-about-follows',
11 templateUrl: './about-follows.component.html',
12 styleUrls: [ './about-follows.component.scss' ]
15 export class AboutFollowsComponent implements OnInit {
16 followers: string[] = []
17 followings: string[] = []
19 followersPagination: ComponentPagination = {
25 followingsPagination: ComponentPagination = {
36 onDataSubject = new Subject<any[]>()
39 private restService: RestService,
40 private notifier: Notifier,
41 private followService: FollowService
45 this.loadMoreFollowers()
47 this.loadMoreFollowings()
51 this.onNearOfFollowersBottom()
53 this.onNearOfFollowingsBottom()
56 onNearOfFollowersBottom () {
57 if (!hasMoreItems(this.followersPagination)) return
59 this.followersPagination.currentPage += 1
60 this.loadMoreFollowers()
63 onNearOfFollowingsBottom () {
64 if (!hasMoreItems(this.followingsPagination)) return
66 this.followingsPagination.currentPage += 1
67 this.loadMoreFollowings()
70 buildLink (host: string) {
71 return window.location.protocol + '//' + host
74 private loadMoreFollowers () {
75 const pagination = this.restService.componentPaginationToRestPagination(this.followersPagination)
77 this.followService.getFollowers({ pagination: pagination, sort: this.sort, state: 'accepted' })
80 const newFollowers = resultList.data.map(r => r.follower.host)
81 this.followers = this.followers.concat(newFollowers)
83 this.followersPagination.totalItems = resultList.total
85 this.onDataSubject.next(newFollowers)
88 err => this.notifier.error(err.message)
92 private loadMoreFollowings () {
93 const pagination = this.restService.componentPaginationToRestPagination(this.followingsPagination)
95 this.followService.getFollowing({ pagination, sort: this.sort, state: 'accepted' })
98 const newFollowings = resultList.data.map(r => r.following.host)
99 this.followings = this.followings.concat(newFollowings)
101 this.followingsPagination.totalItems = resultList.total
103 this.onDataSubject.next(newFollowings)
106 err => this.notifier.error(err.message)