Skip to content

Commit 41afcf9

Browse files
committed
130484: Correctly update the 'showLoadMoreLink$' observable
1 parent d3b48f4 commit 41afcf9

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.component.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
map,
3131
switchMap,
3232
take,
33-
tap,
3433
} from 'rxjs/operators';
3534
import { AlertComponent } from 'src/app/shared/alert/alert.component';
3635
import { AlertType } from 'src/app/shared/alert/alert-type';
@@ -239,27 +238,30 @@ 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.updateBundlesSubject(bundles);
241+
).subscribe((bundles: PaginatedList<Bundle>) => {
242+
this.updateBundles(bundles);
248243
});
249244
}
250245

251-
updateBundlesSubject(newBundles: Bundle[]) {
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>) {
252251
const currentBundles = this.bundlesSubject.getValue();
253252
const bundlesToAdd: Bundle[] = [];
254253

255254
// Only add bundles to the bundle subject if they are not present yet
256-
newBundles.forEach(newBundle => {
255+
newBundlesPL.page.forEach(newBundle => {
257256
if (!currentBundles.some(currentBundle => currentBundle.id === newBundle.id)) {
258257
bundlesToAdd.push(newBundle);
259258
}
260259
});
261260

262-
this.bundlesSubject.next([...currentBundles, ...bundlesToAdd]);
261+
const updatedBundles = [...currentBundles, ...bundlesToAdd];
262+
263+
this.showLoadMoreLink$.next(updatedBundles.length < newBundlesPL.totalElements);
264+
this.bundlesSubject.next(updatedBundles);
263265
}
264266

265267

0 commit comments

Comments
 (0)