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'
9 selector: 'my-about-follows',
10 templateUrl: './about-follows.component.html',
11 styleUrls: [ './about-follows.component.scss' ]
14 export class AboutFollowsComponent implements OnInit {
15 followers: string[] = []
16 followings: string[] = []
18 followersPagination: ComponentPagination = {
24 followingsPagination: ComponentPagination = {
36 private restService: RestService,
37 private notifier: Notifier,
38 private followService: FollowService
42 this.loadMoreFollowers()
44 this.loadMoreFollowings()
48 this.onNearOfFollowersBottom()
50 this.onNearOfFollowingsBottom()
53 onNearOfFollowersBottom () {
54 if (!hasMoreItems(this.followersPagination)) return
56 this.followersPagination.currentPage += 1
57 this.loadMoreFollowers()
60 onNearOfFollowingsBottom () {
61 if (!hasMoreItems(this.followingsPagination)) return
63 this.followingsPagination.currentPage += 1
64 this.loadMoreFollowings()
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, this.sort)
77 const newFollowers = resultList.data.map(r => r.follower.host)
78 this.followers = this.followers.concat(newFollowers)
80 this.followersPagination.totalItems = resultList.total
83 err => this.notifier.error(err.message)
87 private loadMoreFollowings () {
88 const pagination = this.restService.componentPaginationToRestPagination(this.followingsPagination)
90 this.followService.getFollowing(pagination, this.sort)
93 const newFollowings = resultList.data.map(r => r.following.host)
94 this.followings = this.followings.concat(newFollowings)
96 this.followingsPagination.totalItems = resultList.total
99 err => this.notifier.error(err.message)