diff --git a/src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.component.ts b/src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.component.ts index 3399864f4f..adb6b3ef55 100644 --- a/src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.component.ts +++ b/src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.component.ts @@ -32,7 +32,6 @@ import { map, switchMap, take, - tap, } from 'rxjs/operators'; import { AlertComponent } from 'src/app/shared/alert/alert.component'; import { AlertType } from 'src/app/shared/alert/alert-type'; @@ -243,27 +242,30 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme this.itemService.getBundles(this.item.id, new PaginatedSearchOptions({ pagination: this.bundlesOptions })).pipe( getFirstSucceededRemoteData(), getRemoteDataPayload(), - tap((bundlesPL: PaginatedList) => - this.showLoadMoreLink$.next(bundlesPL.pageInfo.currentPage < bundlesPL.pageInfo.totalPages), - ), - map((bundlePage: PaginatedList) => bundlePage.page), - ).subscribe((bundles: Bundle[]) => { - this.updateBundlesSubject(bundles); + ).subscribe((bundles: PaginatedList) => { + this.updateBundles(bundles); }); } - updateBundlesSubject(newBundles: Bundle[]) { + /** + * Update the subject containing the bundles with the provided bundles. + * Also updates the showLoadMoreLink observable so it does not show up when it is no longer necessary. + */ + updateBundles(newBundlesPL: PaginatedList) { const currentBundles = this.bundlesSubject.getValue(); const bundlesToAdd: Bundle[] = []; // Only add bundles to the bundle subject if they are not present yet - newBundles.forEach(newBundle => { + newBundlesPL.page.forEach(newBundle => { if (!currentBundles.some(currentBundle => currentBundle.id === newBundle.id)) { bundlesToAdd.push(newBundle); } }); - this.bundlesSubject.next([...currentBundles, ...bundlesToAdd]); + const updatedBundles = [...currentBundles, ...bundlesToAdd]; + + this.showLoadMoreLink$.next(updatedBundles.length < newBundlesPL.totalElements); + this.bundlesSubject.next(updatedBundles); }