From d803287d0ac1fb8db6351e0b0d6215f1fce55a7a Mon Sep 17 00:00:00 2001 From: aziz Date: Tue, 16 Jan 2024 18:54:22 +0100 Subject: [PATCH 1/5] fix(geo): check catalog not undefined before loading iteams --- .../catalog-browser-tool/catalog-browser-tool.component.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts b/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts index 30a4aaa93a..c8cdeeb7da 100644 --- a/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts +++ b/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts @@ -94,7 +94,9 @@ export class CatalogBrowserToolComponent implements OnInit, OnDestroy { }); this.authenticate$$ = this.authService.authenticate$.subscribe(() => { - this.loadCatalogItems(this.catalog); + if (this.catalog) { + this.loadCatalogItems(this.catalog); + } }); } From bbca69a20d926bcb7298d4bfe2ded82aecf32c37 Mon Sep 17 00:00:00 2001 From: aziz Date: Wed, 17 Jan 2024 20:40:45 +0100 Subject: [PATCH 2/5] solve observable concurrence between catalog and auth --- .../catalog-browser-tool.component.ts | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts b/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts index c8cdeeb7da..7797d876c0 100644 --- a/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts +++ b/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts @@ -16,8 +16,8 @@ import { IgoMap } from '@igo2/geo'; -import { BehaviorSubject, Subscription } from 'rxjs'; -import { take } from 'rxjs/operators'; +import { BehaviorSubject, Subscription, concat } from 'rxjs'; +import { first, take } from 'rxjs/operators'; import { MapState } from '../../map/map.state'; import { CatalogState } from '../catalog.state'; @@ -82,22 +82,18 @@ export class CatalogBrowserToolComponent implements OnInit, OnDestroy { */ ngOnInit() { const catalogStore = this.catalogState.catalogStore; - this.catalog$$ = catalogStore.stateView - .firstBy$( - (record: EntityRecord) => record.state.selected === true - ) - .subscribe((record: EntityRecord) => { - if (record && record.entity) { - const catalog = record.entity; - this.catalog = catalog; - } - }); - this.authenticate$$ = this.authService.authenticate$.subscribe(() => { - if (this.catalog) { + const catalog = catalogStore.stateView.firstBy$( + (record: EntityRecord) => record.state.selected === true + ); + const authenticate = this.authService.authenticate$; + this.catalog$$ = concat(catalog, authenticate) + .pipe(first()) + .subscribe((record) => { + const catalog = (record as EntityRecord).entity; + this.catalog = catalog; this.loadCatalogItems(this.catalog); - } - }); + }); } /** @@ -105,7 +101,7 @@ export class CatalogBrowserToolComponent implements OnInit, OnDestroy { */ ngOnDestroy() { this.catalog$$.unsubscribe(); - this.authenticate$$.unsubscribe(); + // this.authenticate$$.unsubscribe(); } /** From 80deff89fa0cf7565e19f55b59912db51351b995 Mon Sep 17 00:00:00 2001 From: aziz Date: Wed, 17 Jan 2024 20:42:10 +0100 Subject: [PATCH 3/5] delete unusable variable --- .../catalog-browser-tool/catalog-browser-tool.component.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts b/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts index 7797d876c0..6088fe3e03 100644 --- a/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts +++ b/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts @@ -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 */ @@ -101,7 +96,6 @@ export class CatalogBrowserToolComponent implements OnInit, OnDestroy { */ ngOnDestroy() { this.catalog$$.unsubscribe(); - // this.authenticate$$.unsubscribe(); } /** From 00172690dc5682d0ee351d8ad957c41c40cea21c Mon Sep 17 00:00:00 2001 From: aziz Date: Thu, 18 Jan 2024 16:28:52 +0100 Subject: [PATCH 4/5] replace concat by combineLatest ti ensure we have results from two observabels --- .../catalog-browser-tool.component.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts b/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts index 6088fe3e03..22fe64b599 100644 --- a/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts +++ b/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts @@ -16,8 +16,8 @@ import { IgoMap } from '@igo2/geo'; -import { BehaviorSubject, Subscription, concat } from 'rxjs'; -import { first, take } from 'rxjs/operators'; +import { BehaviorSubject, Subscription, combineLatest } from 'rxjs'; +import { take } from 'rxjs/operators'; import { MapState } from '../../map/map.state'; import { CatalogState } from '../catalog.state'; @@ -78,17 +78,17 @@ export class CatalogBrowserToolComponent implements OnInit, OnDestroy { ngOnInit() { const catalogStore = this.catalogState.catalogStore; - const catalog = catalogStore.stateView.firstBy$( + const catalog$ = catalogStore.stateView.firstBy$( (record: EntityRecord) => record.state.selected === true ); - const authenticate = this.authService.authenticate$; - this.catalog$$ = concat(catalog, authenticate) - .pipe(first()) - .subscribe((record) => { - const catalog = (record as EntityRecord).entity; + const authenticate$ = this.authService.authenticate$; + this.catalog$$ = combineLatest([catalog$, authenticate$]).subscribe( + (result) => { + const catalog = result[0].entity; this.catalog = catalog; this.loadCatalogItems(this.catalog); - }); + } + ); } /** From 8617fb8715efcb9394f8faad3020c8d5272c66fa Mon Sep 17 00:00:00 2001 From: aziz Date: Thu, 18 Jan 2024 16:34:14 +0100 Subject: [PATCH 5/5] code improvement --- .../catalog-browser-tool/catalog-browser-tool.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts b/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts index 22fe64b599..15b4852077 100644 --- a/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts +++ b/packages/integration/src/lib/catalog/catalog-browser-tool/catalog-browser-tool.component.ts @@ -83,8 +83,8 @@ export class CatalogBrowserToolComponent implements OnInit, OnDestroy { ); const authenticate$ = this.authService.authenticate$; this.catalog$$ = combineLatest([catalog$, authenticate$]).subscribe( - (result) => { - const catalog = result[0].entity; + ([record, authenticate]) => { + const catalog = record.entity; this.catalog = catalog; this.loadCatalogItems(this.catalog); }