diff options
author | Chocobozzz <me@florianbigard.com> | 2020-12-14 10:23:24 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-12-14 10:23:34 +0100 |
commit | 0d7c73142c3ed3508ff44ab04505256d5443ab19 (patch) | |
tree | 110f11ece542e2eba1746be849899d87a790c625 /client | |
parent | ed8b4014cee544512addfbd75627d2a1cfa0e764 (diff) | |
download | PeerTube-0d7c73142c3ed3508ff44ab04505256d5443ab19.tar.gz PeerTube-0d7c73142c3ed3508ff44ab04505256d5443ab19.tar.zst PeerTube-0d7c73142c3ed3508ff44ab04505256d5443ab19.zip |
Simplify a little bit about follows more logic
Diffstat (limited to 'client')
3 files changed, 38 insertions, 37 deletions
diff --git a/client/src/app/+about/about-follows/about-follows.component.html b/client/src/app/+about/about-follows/about-follows.component.html index 60cf3a28e..c2228b955 100644 --- a/client/src/app/+about/about-follows/about-follows.component.html +++ b/client/src/app/+about/about-follows/about-follows.component.html | |||
@@ -6,16 +6,10 @@ | |||
6 | <div i18n class="no-results" *ngIf="followersPagination.totalItems === 0">This instance does not have instances followers.</div> | 6 | <div i18n class="no-results" *ngIf="followersPagination.totalItems === 0">This instance does not have instances followers.</div> |
7 | 7 | ||
8 | <a *ngFor="let follower of followers" [href]="buildLink(follower)" target="_blank" rel="noopener noreferrer"> | 8 | <a *ngFor="let follower of followers" [href]="buildLink(follower)" target="_blank" rel="noopener noreferrer"> |
9 | {{follower}} | 9 | {{ follower}} |
10 | </a> | 10 | </a> |
11 | <ng-container *ngIf="showMoreFollowers"> | 11 | |
12 | <a *ngFor="let follower of moreFollowers" [href]="buildLink(follower)" target="_blank" rel="noopener noreferrer"> | 12 | <button i18n class="showMore" *ngIf="!loadedAllFollowers && canLoadMoreFollowers()" (click)="loadAllFollowers()">Show full list</button> |
13 | {{ follower }} | ||
14 | </a> | ||
15 | </ng-container> | ||
16 | |||
17 | <button i18n class="showMore" *ngIf="!showMoreFollowers && followersPagination.totalItems > 0" (click)="loadAllFollowers()" (click)="showMoreFollowers=true">Show full list</button> | ||
18 | <button i18n class="showMore" *ngIf="showMoreFollowers" (click)= "showMoreFollowers=false">Show less</button> | ||
19 | </div> | 13 | </div> |
20 | 14 | ||
21 | <div class="col-xl-6 col-md-12"> | 15 | <div class="col-xl-6 col-md-12"> |
@@ -26,14 +20,8 @@ | |||
26 | <a *ngFor="let following of followings" [href]="buildLink(following)" target="_blank" rel="noopener noreferrer"> | 20 | <a *ngFor="let following of followings" [href]="buildLink(following)" target="_blank" rel="noopener noreferrer"> |
27 | {{ following }} | 21 | {{ following }} |
28 | </a> | 22 | </a> |
29 | <ng-container *ngIf="showMoreFollowings"> | 23 | |
30 | <a *ngFor="let following of moreFollowings" [href]="buildLink(following)" target="_blank" rel="noopener noreferrer"> | 24 | <button i18n class="showMore" *ngIf="!loadedAllFollowings && canLoadMoreFollowings()" (click)="loadAllFollowings()">Show full list</button> |
31 | {{ following }} | ||
32 | </a> | ||
33 | </ng-container> | ||
34 | |||
35 | <button i18n class="showMore" *ngIf="!showMoreFollowings && followingsPagination.totalItems > 0" (click)="loadAllFollowings()" (click)="showMoreFollowings=true">Show full list</button> | ||
36 | <button i18n class="showMore" *ngIf="showMoreFollowings" (click)="showMoreFollowings=false">Show less</button> | ||
37 | </div> | 25 | </div> |
38 | 26 | ||
39 | </div> | 27 | </div> |
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) |
diff --git a/client/src/app/shared/shared-instance/instance-follow.service.ts b/client/src/app/shared/shared-instance/instance-follow.service.ts index e52660140..f99dced21 100644 --- a/client/src/app/shared/shared-instance/instance-follow.service.ts +++ b/client/src/app/shared/shared-instance/instance-follow.service.ts | |||
@@ -9,7 +9,7 @@ import { environment } from '../../../environments/environment' | |||
9 | 9 | ||
10 | @Injectable() | 10 | @Injectable() |
11 | export class InstanceFollowService { | 11 | export class InstanceFollowService { |
12 | private static BASE_APPLICATION_URL = environment.apiUrl + '/api/v1/server' | 12 | private static BASE_APPLICATION_URL = 'https://peertube2.cpy.re' + '/api/v1/server' |
13 | 13 | ||
14 | constructor ( | 14 | constructor ( |
15 | private authHttp: HttpClient, | 15 | private authHttp: HttpClient, |