diff --git a/web/projects/ui/src/app/app.providers.ts b/web/projects/ui/src/app/app.providers.ts index 00ff64690..101d402b3 100644 --- a/web/projects/ui/src/app/app.providers.ts +++ b/web/projects/ui/src/app/app.providers.ts @@ -1,14 +1,16 @@ -import { APP_INITIALIZER, Provider } from '@angular/core' +import { APP_INITIALIZER, inject, Provider } from '@angular/core' import { UntypedFormBuilder } from '@angular/forms' import { Router, RouteReuseStrategy } from '@angular/router' import { IonicRouteStrategy, IonNav } from '@ionic/angular' import { RELATIVE_URL, THEME, WorkspaceConfig } from '@start9labs/shared' -import { TUI_ICONS_PATH } from '@taiga-ui/core' +import { TUI_DIALOGS_CLOSE, TUI_ICONS_PATH } from '@taiga-ui/core' import { PatchDB } from 'patch-db-client' +import { filter, pairwise } from 'rxjs' import { PATCH_CACHE, PatchDbSource, } from 'src/app/services/patch-db/patch-db-source' +import { StateService } from 'src/app/services/state.service' import { ApiService } from './services/api/embassy-api.service' import { MockApiService } from './services/api/embassy-mock-api.service' import { LiveApiService } from './services/api/embassy-live-api.service' @@ -58,6 +60,17 @@ export const APP_PROVIDERS: Provider[] = [ provide: TUI_ICONS_PATH, useValue: (name: string) => `/assets/taiga-ui/icons/${name}.svg#${name}`, }, + { + provide: TUI_DIALOGS_CLOSE, + useFactory: () => + inject(StateService).pipe( + pairwise(), + filter( + ([prev, curr]) => + prev === 'running' && (curr === 'error' || curr === 'initializing'), + ), + ), + }, ] export function appInitializer( diff --git a/web/projects/ui/src/app/services/patch-db/patch-db-source.ts b/web/projects/ui/src/app/services/patch-db/patch-db-source.ts index d5ef3364e..00ab3d43e 100644 --- a/web/projects/ui/src/app/services/patch-db/patch-db-source.ts +++ b/web/projects/ui/src/app/services/patch-db/patch-db-source.ts @@ -5,6 +5,7 @@ import { bufferTime, catchError, filter, + skip, startWith, switchMap, take, @@ -41,8 +42,8 @@ export class PatchDbSource extends Observable[]> { catchError((_, original$) => { this.state.retrigger() - // @TODO Alex this is returning right away and crashing the browser, but we need to wait until state emits again from the retrigger() above. return this.state.pipe( + skip(1), // skipping previous value stored due to shareReplay filter(current => current === 'running'), take(1), switchMap(() => original$), diff --git a/web/projects/ui/src/app/services/state.service.ts b/web/projects/ui/src/app/services/state.service.ts index d1dd3b383..9eb8caf0a 100644 --- a/web/projects/ui/src/app/services/state.service.ts +++ b/web/projects/ui/src/app/services/state.service.ts @@ -111,7 +111,7 @@ export class StateService extends Observable { ), ), ) - .subscribe() // @TODO Alex shouldn't this be subscribed in app component with the others? Do we ever need to unsubscribe? + .subscribe() constructor() { super(subscriber => this.stream$.subscribe(subscriber))