Skip to content

Commit 501ccfe

Browse files
committed
130484: Correctly update the 'showLoadMoreLink$' observable
1 parent 02be3e0 commit 501ccfe

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.component.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ChangeDetectorRef, Component, NgZone, OnDestroy, HostListener } from '@angular/core';
22
import { AbstractItemUpdateComponent } from '../abstract-item-update/abstract-item-update.component';
33
import { map, switchMap, take } from 'rxjs/operators';
4-
import { Observable, Subscription, combineLatest, BehaviorSubject, tap } from 'rxjs';
4+
import { Observable, Subscription, combineLatest, BehaviorSubject } from 'rxjs';
55
import { ItemDataService } from '../../../core/data/item-data.service';
66
import { ObjectUpdatesService } from '../../../core/data/object-updates/object-updates.service';
77
import { ActivatedRoute, Router } from '@angular/router';
@@ -187,27 +187,30 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
187187
this.itemService.getBundles(this.item.id, new PaginatedSearchOptions({pagination: this.bundlesOptions})).pipe(
188188
getFirstSucceededRemoteData(),
189189
getRemoteDataPayload(),
190-
tap((bundlesPL: PaginatedList<Bundle>) =>
191-
this.showLoadMoreLink$.next(bundlesPL.pageInfo.currentPage < bundlesPL.pageInfo.totalPages)
192-
),
193-
map((bundlePage: PaginatedList<Bundle>) => bundlePage.page),
194-
).subscribe((bundles: Bundle[]) => {
195-
this.updateBundlesSubject(bundles);
190+
).subscribe((bundles: PaginatedList<Bundle>) => {
191+
this.updateBundles(bundles);
196192
});
197193
}
198194

199-
updateBundlesSubject(newBundles: Bundle[]) {
195+
/**
196+
* Update the subject containing the bundles with the provided bundles.
197+
* Also updates the showLoadMoreLink observable so it does not show up when it is no longer necessary.
198+
*/
199+
updateBundles(newBundlesPL: PaginatedList<Bundle>) {
200200
const currentBundles = this.bundlesSubject.getValue();
201201
const bundlesToAdd: Bundle[] = [];
202202

203203
// Only add bundles to the bundle subject if they are not present yet
204-
newBundles.forEach(newBundle => {
204+
newBundlesPL.page.forEach(newBundle => {
205205
if (!currentBundles.some(currentBundle => currentBundle.id === newBundle.id)) {
206206
bundlesToAdd.push(newBundle);
207207
}
208208
});
209209

210-
this.bundlesSubject.next([...currentBundles, ...bundlesToAdd]);
210+
const updatedBundles = [...currentBundles, ...bundlesToAdd];
211+
212+
this.showLoadMoreLink$.next(updatedBundles.length < newBundlesPL.totalElements);
213+
this.bundlesSubject.next(updatedBundles);
211214
}
212215

213216

0 commit comments

Comments
 (0)