diff --git a/src/app/pages/apps/store/installed-apps-store.service.ts b/src/app/pages/apps/store/installed-apps-store.service.ts index dbbf80a41da..3964cc10a3f 100644 --- a/src/app/pages/apps/store/installed-apps-store.service.ts +++ b/src/app/pages/apps/store/installed-apps-store.service.ts @@ -7,6 +7,7 @@ import { withLatestFrom, } from 'rxjs'; import { IncomingApiMessageType } from 'app/enums/api-message-type.enum'; +import { tapOnce } from 'app/helpers/operators/tap-once.operator'; import { ApiEvent } from 'app/interfaces/api-message.interface'; import { App } from 'app/interfaces/app.interface'; import { AvailableApp } from 'app/interfaces/available-app.interface'; @@ -42,6 +43,7 @@ export class InstalledAppsStore extends ComponentStore imple ) { super(initialState); this.initialize(); + this.getStats(); } readonly initialize = this.effect((triggers$: Observable) => { @@ -61,6 +63,18 @@ export class InstalledAppsStore extends ComponentStore imple ); }); + readonly getStats = this.effect(() => { + return this.installedApps$.pipe( + filter((apps) => apps.length > 0), + tapOnce(() => this.appsStats.subscribeToUpdates()), + catchError((error: unknown) => { + this.handleError(error); + return EMPTY; + }), + untilDestroyed(this), + ); + }); + private handleError(error: unknown): void { this.errorHandler.showErrorModal(error); this.patchState({ @@ -68,12 +82,11 @@ export class InstalledAppsStore extends ComponentStore imple }); } - private loadInstalledApps(): Observable { + private loadInstalledApps(): Observable { return this.dockerStore.isLoading$.pipe( withLatestFrom(this.dockerStore.isDockerStarted$), filter(([isLoading, isDockerStarted]) => !isLoading && isDockerStarted !== null), switchMap(([, isDockerStarted]) => { - this.appsStats.subscribeToUpdates(); this.subscribeToInstalledAppsUpdates(); if (!isDockerStarted) {