fix an issue where the results of a dso-selector wouldn't update until you clicked anywhere on the page

This commit is contained in:
Art Lowel
2021-06-23 17:28:36 +02:00
parent 2599068ccd
commit 04f4a25870
2 changed files with 11 additions and 10 deletions

View File

@@ -14,12 +14,12 @@
[infiniteScrollContainer]="'.scrollable-menu'" [infiniteScrollContainer]="'.scrollable-menu'"
[fromRoot]="true" [fromRoot]="true"
(scrolled)="onScrollDown()"> (scrolled)="onScrollDown()">
<ng-container *ngIf="listEntries"> <ng-container *ngIf="listEntries$ | async">
<button class="list-group-item list-group-item-action border-0 disabled" <button class="list-group-item list-group-item-action border-0 disabled"
*ngIf="listEntries.length == 0"> *ngIf="(listEntries$ | async).length == 0">
{{'dso-selector.no-results' | translate: { type: typesString } }} {{'dso-selector.no-results' | translate: { type: typesString } }}
</button> </button>
<button *ngFor="let listEntry of listEntries" <button *ngFor="let listEntry of (listEntries$ | async)"
class="list-group-item list-group-item-action border-0 list-entry" class="list-group-item list-group-item-action border-0 list-entry"
[ngClass]="{'bg-primary': listEntry.indexableObject.id === currentDSOId}" [ngClass]="{'bg-primary': listEntry.indexableObject.id === currentDSOId}"
title="{{ listEntry.indexableObject.name }}" title="{{ listEntry.indexableObject.name }}"

View File

@@ -81,7 +81,7 @@ export class DSOSelectorComponent implements OnInit, OnDestroy {
/** /**
* List with search results of DSpace objects for the current query * List with search results of DSpace objects for the current query
*/ */
listEntries: SearchResult<DSpaceObject>[] = null; listEntries$: BehaviorSubject<SearchResult<DSpaceObject>[]> = new BehaviorSubject(null);
/** /**
* The current page to load * The current page to load
@@ -160,7 +160,7 @@ export class DSOSelectorComponent implements OnInit, OnDestroy {
this.loading = true; this.loading = true;
if (page === 1) { if (page === 1) {
// The first page is loading, this means we should reset the list instead of adding to it // The first page is loading, this means we should reset the list instead of adding to it
this.listEntries = null; this.listEntries$.next(null);
} }
return this.search(query, page).pipe( return this.search(query, page).pipe(
map((rd) => { map((rd) => {
@@ -181,15 +181,16 @@ export class DSOSelectorComponent implements OnInit, OnDestroy {
).subscribe((rd) => { ).subscribe((rd) => {
this.loading = false; this.loading = false;
if (rd.hasSucceeded) { if (rd.hasSucceeded) {
if (hasNoValue(this.listEntries)) { const currentEntries = this.listEntries$.getValue();
this.listEntries = rd.payload.page; if (hasNoValue(currentEntries)) {
this.listEntries$.next(rd.payload.page);
} else { } else {
this.listEntries.push(...rd.payload.page); this.listEntries$.next([...currentEntries, ...rd.payload.page]);
} }
// Check if there are more pages available after the current one // Check if there are more pages available after the current one
this.hasNextPage = rd.payload.totalElements > this.listEntries.length; this.hasNextPage = rd.payload.totalElements > this.listEntries$.getValue().length;
} else { } else {
this.listEntries = null; this.listEntries$.next(null);
this.hasNextPage = false; this.hasNextPage = false;
} }
})); }));