Skip to content

Commit

Permalink
fix(geo): check catalog not undefined before loading items (#1583)
Browse files Browse the repository at this point in the history
  • Loading branch information
aziz-access authored Jan 19, 2024
1 parent 297f96e commit 1efb4a6
Showing 1 changed file with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
IgoMap
} from '@igo2/geo';

import { BehaviorSubject, Subscription } from 'rxjs';
import { BehaviorSubject, Subscription, combineLatest } from 'rxjs';
import { take } from 'rxjs/operators';

import { MapState } from '../../map/map.state';
Expand Down Expand Up @@ -52,11 +52,6 @@ export class CatalogBrowserToolComponent implements OnInit, OnDestroy {
*/
private catalog$$: Subscription;

/**
* Subscription for authentication
*/
private authenticate$$: Subscription;

/**
* Whether a group can be toggled when it's collapsed
*/
Expand All @@ -82,28 +77,25 @@ export class CatalogBrowserToolComponent implements OnInit, OnDestroy {
*/
ngOnInit() {
const catalogStore = this.catalogState.catalogStore;
this.catalog$$ = catalogStore.stateView
.firstBy$(
(record: EntityRecord<Catalog>) => record.state.selected === true
)
.subscribe((record: EntityRecord<Catalog>) => {
if (record && record.entity) {
const catalog = record.entity;
this.catalog = catalog;
}
});

this.authenticate$$ = this.authService.authenticate$.subscribe(() => {
this.loadCatalogItems(this.catalog);
});
const catalog$ = catalogStore.stateView.firstBy$(
(record: EntityRecord<Catalog>) => record.state.selected === true
);
const authenticate$ = this.authService.authenticate$;
this.catalog$$ = combineLatest([catalog$, authenticate$]).subscribe(
([record, authenticate]) => {
const catalog = record.entity;
this.catalog = catalog;
this.loadCatalogItems(this.catalog);
}
);
}

/**
* @internal
*/
ngOnDestroy() {
this.catalog$$.unsubscribe();
this.authenticate$$.unsubscribe();
}

/**
Expand Down

0 comments on commit 1efb4a6

Please sign in to comment.