130484: Only add bundles when they are missing from the subject

This commit is contained in:
Andreas Awouters
2025-04-30 13:42:51 +02:00
parent 5719f06dd1
commit d3b48f4ea4

View File

@@ -244,10 +244,24 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
), ),
map((bundlePage: PaginatedList<Bundle>) => bundlePage.page), map((bundlePage: PaginatedList<Bundle>) => bundlePage.page),
).subscribe((bundles: Bundle[]) => { ).subscribe((bundles: Bundle[]) => {
this.bundlesSubject.next([...this.bundlesSubject.getValue(), ...bundles]); this.updateBundlesSubject(bundles);
}); });
} }
updateBundlesSubject(newBundles: Bundle[]) {
const currentBundles = this.bundlesSubject.getValue();
const bundlesToAdd: Bundle[] = [];
// Only add bundles to the bundle subject if they are not present yet
newBundles.forEach(newBundle => {
if (!currentBundles.some(currentBundle => currentBundle.id === newBundle.id)) {
bundlesToAdd.push(newBundle);
}
});
this.bundlesSubject.next([...currentBundles, ...bundlesToAdd]);
}
/** /**
* Submit the current changes * Submit the current changes