aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+about/about-follows/about-follows.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-12-14 10:23:24 +0100
committerChocobozzz <me@florianbigard.com>2020-12-14 10:23:34 +0100
commit0d7c73142c3ed3508ff44ab04505256d5443ab19 (patch)
tree110f11ece542e2eba1746be849899d87a790c625 /client/src/app/+about/about-follows/about-follows.component.ts
parented8b4014cee544512addfbd75627d2a1cfa0e764 (diff)
downloadPeerTube-0d7c73142c3ed3508ff44ab04505256d5443ab19.tar.gz
PeerTube-0d7c73142c3ed3508ff44ab04505256d5443ab19.tar.zst
PeerTube-0d7c73142c3ed3508ff44ab04505256d5443ab19.zip
Simplify a little bit about follows more logic
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.ts51
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 @@
1import { SortMeta } from 'primeng/api' 1import { SortMeta } from 'primeng/api'
2import { Subject } from 'rxjs'
3import { Component, OnInit } from '@angular/core' 2import { Component, OnInit } from '@angular/core'
4import { ComponentPagination, hasMoreItems, Notifier, RestService } from '@app/core' 3import { ComponentPagination, hasMoreItems, Notifier, RestService } from '@app/core'
5import { InstanceFollowService } from '@app/shared/shared-instance' 4import { InstanceFollowService } from '@app/shared/shared-instance'
@@ -13,11 +12,9 @@ import { InstanceFollowService } from '@app/shared/shared-instance'
13export class AboutFollowsComponent implements OnInit { 12export 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)