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 da12147043
commit 02be3e0ad5

View File

@@ -192,10 +192,24 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
),
map((bundlePage: PaginatedList<Bundle>) => bundlePage.page),
).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