diff options
Diffstat (limited to 'client/src/app/+about/about-follows/about-follows.component.ts')
-rw-r--r-- | client/src/app/+about/about-follows/about-follows.component.ts | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/client/src/app/+about/about-follows/about-follows.component.ts b/client/src/app/+about/about-follows/about-follows.component.ts index b808c1ac9..d335cbf45 100644 --- a/client/src/app/+about/about-follows/about-follows.component.ts +++ b/client/src/app/+about/about-follows/about-follows.component.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import { SortMeta } from 'primeng/api' | 1 | import { SortMeta } from 'primeng/api' |
2 | import { Subject } from 'rxjs' | ||
3 | import { Component, OnInit } from '@angular/core' | 2 | import { Component, OnInit } from '@angular/core' |
4 | import { ComponentPagination, hasMoreItems, Notifier, RestService } from '@app/core' | 3 | import { ComponentPagination, hasMoreItems, Notifier, RestService } from '@app/core' |
5 | import { InstanceFollowService } from '@app/shared/shared-instance' | 4 | import { InstanceFollowService } from '@app/shared/shared-instance' |
@@ -13,11 +12,9 @@ import { InstanceFollowService } from '@app/shared/shared-instance' | |||
13 | export class AboutFollowsComponent implements OnInit { | 12 | export class AboutFollowsComponent implements OnInit { |
14 | followers: string[] = [] | 13 | followers: string[] = [] |
15 | followings: string[] = [] | 14 | followings: string[] = [] |
16 | moreFollowers: string[] = [] | ||
17 | moreFollowings: string[] = [] | ||
18 | 15 | ||
19 | showMoreFollowers = false | 16 | loadedAllFollowers = false |
20 | showMoreFollowings = false | 17 | loadedAllFollowings = false |
21 | 18 | ||
22 | followersPagination: ComponentPagination = { | 19 | followersPagination: ComponentPagination = { |
23 | currentPage: 1, | 20 | currentPage: 1, |
@@ -36,8 +33,6 @@ export class AboutFollowsComponent implements OnInit { | |||
36 | order: -1 | 33 | order: -1 |
37 | } | 34 | } |
38 | 35 | ||
39 | onDataSubject = new Subject<any[]>() | ||
40 | |||
41 | constructor ( | 36 | constructor ( |
42 | private restService: RestService, | 37 | private restService: RestService, |
43 | private notifier: Notifier, | 38 | private notifier: Notifier, |
@@ -51,6 +46,13 @@ export class AboutFollowsComponent implements OnInit { | |||
51 | } | 46 | } |
52 | 47 | ||
53 | loadAllFollowings () { | 48 | loadAllFollowings () { |
49 | if (this.loadedAllFollowings) return | ||
50 | |||
51 | this.loadedAllFollowings = true | ||
52 | this.followingsPagination.itemsPerPage = 100 | ||
53 | |||
54 | this.loadMoreFollowings(true) | ||
55 | |||
54 | while (hasMoreItems(this.followingsPagination)) { | 56 | while (hasMoreItems(this.followingsPagination)) { |
55 | this.followingsPagination.currentPage += 1 | 57 | this.followingsPagination.currentPage += 1 |
56 | 58 | ||
@@ -59,6 +61,13 @@ export class AboutFollowsComponent implements OnInit { | |||
59 | } | 61 | } |
60 | 62 | ||
61 | loadAllFollowers () { | 63 | loadAllFollowers () { |
64 | if (this.loadedAllFollowers) return | ||
65 | |||
66 | this.loadedAllFollowers = true | ||
67 | this.followersPagination.itemsPerPage = 100 | ||
68 | |||
69 | this.loadMoreFollowers(true) | ||
70 | |||
62 | while (hasMoreItems(this.followersPagination)) { | 71 | while (hasMoreItems(this.followersPagination)) { |
63 | this.followersPagination.currentPage += 1 | 72 | this.followersPagination.currentPage += 1 |
64 | 73 | ||
@@ -70,40 +79,44 @@ export class AboutFollowsComponent implements OnInit { | |||
70 | return window.location.protocol + '//' + host | 79 | return window.location.protocol + '//' + host |
71 | } | 80 | } |
72 | 81 | ||
73 | private loadMoreFollowers () { | 82 | canLoadMoreFollowers () { |
83 | return this.loadedAllFollowers || this.followersPagination.totalItems > this.followersPagination.itemsPerPage | ||
84 | } | ||
85 | |||
86 | canLoadMoreFollowings () { | ||
87 | return this.loadedAllFollowings || this.followingsPagination.totalItems > this.followingsPagination.itemsPerPage | ||
88 | } | ||
89 | |||
90 | private loadMoreFollowers (reset = false) { | ||
74 | const pagination = this.restService.componentPaginationToRestPagination(this.followersPagination) | 91 | const pagination = this.restService.componentPaginationToRestPagination(this.followersPagination) |
75 | 92 | ||
76 | this.followService.getFollowers({ pagination: pagination, sort: this.sort, state: 'accepted' }) | 93 | this.followService.getFollowers({ pagination: pagination, sort: this.sort, state: 'accepted' }) |
77 | .subscribe( | 94 | .subscribe( |
78 | resultList => { | 95 | resultList => { |
79 | const newFollowers = resultList.data.map(r => r.follower.host) | 96 | if (reset) this.followers = [] |
80 | if (this.followers.length === 0) this.followers = this.followers.concat(newFollowers) | ||
81 | 97 | ||
82 | else this.moreFollowers = this.moreFollowers.concat(newFollowers) | 98 | const newFollowers = resultList.data.map(r => r.follower.host) |
99 | this.followers = this.followers.concat(newFollowers) | ||
83 | 100 | ||
84 | this.followersPagination.totalItems = resultList.total | 101 | this.followersPagination.totalItems = resultList.total |
85 | |||
86 | this.onDataSubject.next(newFollowers) | ||
87 | }, | 102 | }, |
88 | 103 | ||
89 | err => this.notifier.error(err.message) | 104 | err => this.notifier.error(err.message) |
90 | ) | 105 | ) |
91 | } | 106 | } |
92 | 107 | ||
93 | private loadMoreFollowings () { | 108 | private loadMoreFollowings (reset = false) { |
94 | const pagination = this.restService.componentPaginationToRestPagination(this.followingsPagination) | 109 | const pagination = this.restService.componentPaginationToRestPagination(this.followingsPagination) |
95 | 110 | ||
96 | this.followService.getFollowing({ pagination, sort: this.sort, state: 'accepted' }) | 111 | this.followService.getFollowing({ pagination, sort: this.sort, state: 'accepted' }) |
97 | .subscribe( | 112 | .subscribe( |
98 | resultList => { | 113 | resultList => { |
99 | const newFollowings = resultList.data.map(r => r.following.host) | 114 | if (reset) this.followings = [] |
100 | if (this.followings.length === 0) this.followings = this.followings.concat(newFollowings) | ||
101 | 115 | ||
102 | else this.moreFollowings = this.moreFollowings.concat(newFollowings) | 116 | const newFollowings = resultList.data.map(r => r.following.host) |
117 | this.followings = this.followings.concat(newFollowings) | ||
103 | 118 | ||
104 | this.followingsPagination.totalItems = resultList.total | 119 | this.followingsPagination.totalItems = resultList.total |
105 | |||
106 | this.onDataSubject.next(newFollowings) | ||
107 | }, | 120 | }, |
108 | 121 | ||
109 | err => this.notifier.error(err.message) | 122 | err => this.notifier.error(err.message) |