1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-22 11:45:59 +01:00

ref ciphers paging from jslib

This commit is contained in:
Kyle Spearrin 2019-03-19 11:34:34 -04:00
parent 44a98bb1bc
commit eb07b1b080
5 changed files with 8 additions and 41 deletions

2
jslib

@ -1 +1 @@
Subproject commit d4c2b20a2594fcac1fdabf312b7289657b4af0c8
Subproject commit d8f9177c03549667cf6d1e5f30536d010acc7b7d

6
package-lock.json generated
View File

@ -8925,9 +8925,9 @@
"dev": true
},
"ngx-infinite-scroll": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/ngx-infinite-scroll/-/ngx-infinite-scroll-6.0.1.tgz",
"integrity": "sha512-20WcD+3Qh3O0IEFyIjt55JPTKw5W1hAxERXMUDgGDRveS3IBpBxv2DuX5vuHG/bNGC+WoTDlNR/XXScNNicRpw==",
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/ngx-infinite-scroll/-/ngx-infinite-scroll-7.0.1.tgz",
"integrity": "sha512-be9DAAuabV7VGI06/JUnS6pXC6mcBOzA4+SBCwOcP9WwJ2r5GjdZyOa34ls9hi1MnCOj3zrXLvPKQ/UDp6csIw==",
"requires": {
"opencollective": "^1.0.3"
}

View File

@ -94,7 +94,7 @@
"font-awesome": "4.7.0",
"lunr": "2.3.3",
"mousetrap": "1.6.2",
"ngx-infinite-scroll": "6.0.1",
"ngx-infinite-scroll": "7.0.1",
"node-forge": "0.7.6",
"papaparse": "4.6.0",
"rxjs": "6.3.3",

View File

@ -53,7 +53,7 @@
</div>
</div>
</ng-container>
<ng-container *ngIf="(!isPaging() ? ciphers : pagedCiphers) as filteredCiphers">
<ng-container *ngIf="(isPaging() ? pagedCiphers : ciphers) 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">
@ -63,7 +63,7 @@
</button>
</ng-container>
</div>
<div class="box list only-list" *ngIf="filteredCiphers.length > 0" infiniteScroll [infiniteScrollDistance]="1"
<div class="box list only-list" *ngIf="filteredCiphers.length" infiniteScroll [infiniteScrollDistance]="1"
[infiniteScrollContainer]="'content'" [fromRoot]="true" [infiniteScrollDisabled]="!isPaging()"
(scrolled)="loadMore()">
<div class="box-header">

View File

@ -48,15 +48,12 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On
folderId: string = null;
collectionId: string = null;
type: CipherType = null;
pagedCiphers: CipherView[] = [];
nestedFolders: Array<TreeNode<FolderView>>;
nestedCollections: Array<TreeNode<CollectionView>>;
searchTypeSearch = false;
private didScroll = false;
private selectedTimeout: number;
private preventSelected = false;
private pageSize = 100;
private applySavedState = true;
constructor(searchService: SearchService, private route: ActivatedRoute,
@ -67,7 +64,7 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On
private folderService: FolderService, private collectionService: CollectionService,
private analytics: Angulartics2, private platformUtilsService: PlatformUtilsService) {
super(searchService);
this.pageSize = platformUtilsService.isEdge() ? 25 : 100;
this.pageSize = platformUtilsService.isEdge() ? 25 : 10;
this.applySavedState = (window as any).previousPopupUrl != null &&
!(window as any).previousPopupUrl.startsWith('/ciphers');
}
@ -124,7 +121,6 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On
await this.load();
}
this.loadMore();
if (this.applySavedState) {
this.state = (await this.stateService.get<any>(ComponentId)) || {};
if (this.state.searchText) {
@ -214,41 +210,12 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On
this.location.back();
}
loadMore() {
if (this.ciphers.length <= this.pageSize) {
return;
}
const pagedLength = this.pagedCiphers.length;
if (this.ciphers.length > pagedLength) {
this.pagedCiphers = this.pagedCiphers.concat(this.ciphers.slice(pagedLength, pagedLength + this.pageSize));
}
this.didScroll = this.pagedCiphers.length > this.pageSize;
}
showGroupings() {
return !this.isSearching() &&
((this.nestedFolders && this.nestedFolders.length) ||
(this.nestedCollections && this.nestedCollections.length));
}
isSearching() {
return !this.searchPending && this.searchService.isSearchable(this.searchText);
}
isPaging() {
const searching = this.isSearching();
if (searching && this.didScroll) {
this.resetPaging();
}
return !searching && this.ciphers.length > this.pageSize;
}
async resetPaging() {
this.pagedCiphers = [];
this.loadMore();
}
private async saveState() {
this.state = {
scrollY: this.popupUtils.getContentScrollY(window),