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 | 103 |
1 files changed, 103 insertions, 0 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 new file mode 100644 index 000000000..f0e1375d6 --- /dev/null +++ b/client/src/app/+about/about-follows/about-follows.component.ts | |||
@@ -0,0 +1,103 @@ | |||
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 | |||
8 | @Component({ | ||
9 | selector: 'my-about-follows', | ||
10 | templateUrl: './about-follows.component.html', | ||
11 | styleUrls: [ './about-follows.component.scss' ] | ||
12 | }) | ||
13 | |||
14 | export class AboutFollowsComponent implements OnInit { | ||
15 | followers: string[] = [] | ||
16 | followings: string[] = [] | ||
17 | |||
18 | followersPagination: ComponentPagination = { | ||
19 | currentPage: 1, | ||
20 | itemsPerPage: 40, | ||
21 | totalItems: null | ||
22 | } | ||
23 | |||
24 | followingsPagination: ComponentPagination = { | ||
25 | currentPage: 1, | ||
26 | itemsPerPage: 40, | ||
27 | totalItems: null | ||
28 | } | ||
29 | |||
30 | sort: SortMeta = { | ||
31 | field: 'createdAt', | ||
32 | order: -1 | ||
33 | } | ||
34 | |||
35 | constructor ( | ||
36 | private restService: RestService, | ||
37 | private notifier: Notifier, | ||
38 | private followService: FollowService | ||
39 | ) { } | ||
40 | |||
41 | ngOnInit () { | ||
42 | this.loadMoreFollowers() | ||
43 | |||
44 | this.loadMoreFollowings() | ||
45 | } | ||
46 | |||
47 | onNearOfBottom () { | ||
48 | this.onNearOfFollowersBottom() | ||
49 | |||
50 | this.onNearOfFollowingsBottom() | ||
51 | } | ||
52 | |||
53 | onNearOfFollowersBottom () { | ||
54 | if (!hasMoreItems(this.followersPagination)) return | ||
55 | |||
56 | this.followersPagination.currentPage += 1 | ||
57 | this.loadMoreFollowers() | ||
58 | } | ||
59 | |||
60 | onNearOfFollowingsBottom () { | ||
61 | if (!hasMoreItems(this.followingsPagination)) return | ||
62 | |||
63 | this.followingsPagination.currentPage += 1 | ||
64 | this.loadMoreFollowings() | ||
65 | } | ||
66 | |||
67 | buildLink (host: string) { | ||
68 | return window.location.protocol + '//' + host | ||
69 | } | ||
70 | |||
71 | private loadMoreFollowers () { | ||
72 | const pagination = this.restService.componentPaginationToRestPagination(this.followersPagination) | ||
73 | |||
74 | this.followService.getFollowers(pagination, this.sort) | ||
75 | .subscribe( | ||
76 | resultList => { | ||
77 | const newFollowers = resultList.data.map(r => r.follower.host) | ||
78 | this.followers = this.followers.concat(newFollowers) | ||
79 | |||
80 | this.followersPagination.totalItems = resultList.total | ||
81 | }, | ||
82 | |||
83 | err => this.notifier.error(err.message) | ||
84 | ) | ||
85 | } | ||
86 | |||
87 | private loadMoreFollowings () { | ||
88 | const pagination = this.restService.componentPaginationToRestPagination(this.followingsPagination) | ||
89 | |||
90 | this.followService.getFollowing(pagination, this.sort) | ||
91 | .subscribe( | ||
92 | resultList => { | ||
93 | const newFollowings = resultList.data.map(r => r.following.host) | ||
94 | this.followings = this.followings.concat(newFollowings) | ||
95 | |||
96 | this.followingsPagination.totalItems = resultList.total | ||
97 | }, | ||
98 | |||
99 | err => this.notifier.error(err.message) | ||
100 | ) | ||
101 | } | ||
102 | |||
103 | } | ||