|
1 | 1 | import { ChangeDetectorRef, Component, NgZone, OnDestroy, HostListener } from '@angular/core'; |
2 | 2 | import { AbstractItemUpdateComponent } from '../abstract-item-update/abstract-item-update.component'; |
3 | 3 | import { map, switchMap, take } from 'rxjs/operators'; |
4 | | -import { Observable, Subscription, combineLatest, BehaviorSubject, tap } from 'rxjs'; |
| 4 | +import { Observable, Subscription, combineLatest, BehaviorSubject } from 'rxjs'; |
5 | 5 | import { ItemDataService } from '../../../core/data/item-data.service'; |
6 | 6 | import { ObjectUpdatesService } from '../../../core/data/object-updates/object-updates.service'; |
7 | 7 | import { ActivatedRoute, Router } from '@angular/router'; |
@@ -187,27 +187,30 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme |
187 | 187 | this.itemService.getBundles(this.item.id, new PaginatedSearchOptions({pagination: this.bundlesOptions})).pipe( |
188 | 188 | getFirstSucceededRemoteData(), |
189 | 189 | 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); |
196 | 192 | }); |
197 | 193 | } |
198 | 194 |
|
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>) { |
200 | 200 | const currentBundles = this.bundlesSubject.getValue(); |
201 | 201 | const bundlesToAdd: Bundle[] = []; |
202 | 202 |
|
203 | 203 | // Only add bundles to the bundle subject if they are not present yet |
204 | | - newBundles.forEach(newBundle => { |
| 204 | + newBundlesPL.page.forEach(newBundle => { |
205 | 205 | if (!currentBundles.some(currentBundle => currentBundle.id === newBundle.id)) { |
206 | 206 | bundlesToAdd.push(newBundle); |
207 | 207 | } |
208 | 208 | }); |
209 | 209 |
|
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); |
211 | 214 | } |
212 | 215 |
|
213 | 216 |
|
|
0 commit comments