@@ -30,7 +30,6 @@ import {
3030 map ,
3131 switchMap ,
3232 take ,
33- tap ,
3433} from 'rxjs/operators' ;
3534import { AlertComponent } from 'src/app/shared/alert/alert.component' ;
3635import { AlertType } from 'src/app/shared/alert/alert-type' ;
@@ -239,15 +238,28 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
239238 this . itemService . getBundles ( this . item . id , new PaginatedSearchOptions ( { pagination : this . bundlesOptions } ) ) . pipe (
240239 getFirstSucceededRemoteData ( ) ,
241240 getRemoteDataPayload ( ) ,
242- tap ( ( bundlesPL : PaginatedList < Bundle > ) =>
243- this . showLoadMoreLink$ . next ( bundlesPL . pageInfo . currentPage < bundlesPL . pageInfo . totalPages ) ,
244- ) ,
245- map ( ( bundlePage : PaginatedList < Bundle > ) => bundlePage . page ) ,
246- ) . subscribe ( ( bundles : Bundle [ ] ) => {
247- this . bundlesSubject . next ( [ ...this . bundlesSubject . getValue ( ) , ...bundles ] ) ;
241+ ) . subscribe ( ( bundles : PaginatedList < Bundle > ) => {
242+ this . updateBundles ( bundles ) ;
248243 } ) ;
249244 }
250245
246+ /**
247+ * Update the subject containing the bundles with the provided bundles.
248+ * Also updates the showLoadMoreLink observable so it does not show up when it is no longer necessary.
249+ */
250+ updateBundles ( newBundlesPL : PaginatedList < Bundle > ) {
251+ const currentBundles = this . bundlesSubject . getValue ( ) ;
252+
253+ // Only add bundles to the bundle subject if they are not present yet
254+ const bundlesToAdd = newBundlesPL . page
255+ . filter ( bundleToAdd => ! currentBundles . some ( currentBundle => currentBundle . id === bundleToAdd . id ) ) ;
256+
257+ const updatedBundles = [ ...currentBundles , ...bundlesToAdd ] ;
258+
259+ this . showLoadMoreLink$ . next ( updatedBundles . length < newBundlesPL . totalElements ) ;
260+ this . bundlesSubject . next ( updatedBundles ) ;
261+ }
262+
251263
252264 /**
253265 * Submit the current changes
0 commit comments