make paging smarter

This commit is contained in:
Kyle Spearrin 2018-04-11 10:34:39 -04:00
parent 744559516d
commit 45033eb81e
2 changed files with 12 additions and 4 deletions

View File

@ -17,7 +17,7 @@
</div>
</header>
<content>
<ng-container *ngIf="(isSearching() ? (ciphers | searchCiphers: searchText) : pagedCiphers) as filteredCiphers">
<ng-container *ngIf="(!isPaging() ? (ciphers | searchCiphers: searchText) : pagedCiphers) as filteredCiphers">
<div class="no-items" *ngIf="!filteredCiphers.length">
<i class="fa fa-spinner fa-spin fa-3x" *ngIf="!loaded"></i>
<ng-container *ngIf="loaded">
@ -29,7 +29,7 @@
</div>
<div class="box list only-list" *ngIf="filteredCiphers.length > 0"
infiniteScroll [infiniteScrollDistance]="1" [infiniteScrollContainer]="'content'" [fromRoot]="true"
[infiniteScrollDisabled]="isSearching()" (scrolled)="loadMore()">
[infiniteScrollDisabled]="!isPaging()" (scrolled)="loadMore()">
<div class="box-header">
{{groupingTitle}}
<span class="flex-right">{{isSearching() ? filteredCiphers.length : ciphers.length}}</span>

View File

@ -174,6 +174,10 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On
}
loadMore() {
if (this.ciphers.length <= PageSize) {
return;
}
const pagedLength = this.pagedCiphers.length;
if (this.ciphers.length > pagedLength) {
this.pagedCiphers = this.pagedCiphers.concat(this.ciphers.slice(pagedLength, pagedLength + PageSize));
@ -182,11 +186,15 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On
}
isSearching() {
const searching = this.searchText != null && this.searchText.length > 1;
return this.searchText != null && this.searchText.length > 1;
}
isPaging() {
const searching = this.isSearching();
if (searching && this.didScroll) {
this.resetPaging();
}
return searching;
return !searching && this.ciphers.length > PageSize;
}
async resetPaging() {