From aba04913ce24d6ef5988a443347710ae4bad04d6 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Tue, 2 Apr 2024 18:54:39 +0200 Subject: [PATCH] [DURACOM-234] Replace Observable with BehaviorSubject --- ...y-dspace-new-external-dropdown.component.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/app/my-dspace-page/my-dspace-new-submission/my-dspace-new-external-dropdown/my-dspace-new-external-dropdown.component.ts b/src/app/my-dspace-page/my-dspace-new-submission/my-dspace-new-external-dropdown/my-dspace-new-external-dropdown.component.ts index 54830f4198..86960725a5 100644 --- a/src/app/my-dspace-page/my-dspace-new-submission/my-dspace-new-external-dropdown/my-dspace-new-external-dropdown.component.ts +++ b/src/app/my-dspace-page/my-dspace-new-submission/my-dspace-new-external-dropdown/my-dspace-new-external-dropdown.component.ts @@ -11,6 +11,7 @@ import { Router } from '@angular/router'; import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; import { TranslateModule } from '@ngx-translate/core'; import { + BehaviorSubject, Observable, of as observableOf, Subscription, @@ -67,7 +68,7 @@ export class MyDSpaceNewExternalDropdownComponent implements OnInit, OnDestroy { /** * TRUE if the page is initialized */ - public initialized$: Observable; + public initialized$: BehaviorSubject = new BehaviorSubject(false); /** * Array to track all subscriptions and unsubscribe them onDestroy @@ -88,7 +89,6 @@ export class MyDSpaceNewExternalDropdownComponent implements OnInit, OnDestroy { * Initialize entity type list */ ngOnInit() { - this.initialized$ = observableOf(false); this.moreThanOne$ = this.entityTypeService.hasMoreThanOneAuthorizedImport(); this.singleEntity$ = this.moreThanOne$.pipe( mergeMap((response: boolean) => { @@ -98,21 +98,23 @@ export class MyDSpaceNewExternalDropdownComponent implements OnInit, OnDestroy { currentPage: 1, }; return this.entityTypeService.getAllAuthorizedRelationshipTypeImport(findListOptions).pipe( - map((entities: RemoteData>) => { - this.initialized$ = observableOf(true); - return entities.payload.page[0]; - }), take(1), + map((entities: RemoteData>) => { + this.initialized$.next(true); + return entities?.payload?.page[0]; + }), ); } else { - this.initialized$ = observableOf(true); + this.initialized$.next(true); return observableOf(null); } }), take(1), ); this.subs.push( - this.singleEntity$.subscribe((result) => this.singleEntity = result ), + this.singleEntity$.subscribe((result) => { + this.singleEntity = result; + } ), ); }