Skip to content

Commit

Permalink
NAS-131461 / 25.04 / Listen for apps stats only when have installed a…
Browse files Browse the repository at this point in the history
…pps (#10791)

* NAS-131461: Listen for stats when have apps

* NAS-131461: Listen for stats when have apps

* NAS-131461: Listen for apps stats only when have installed apps
  • Loading branch information
denysbutenko authored Oct 7, 2024
1 parent ea5d556 commit e64b7af
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/app/pages/apps/store/installed-apps-store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -42,6 +43,7 @@ export class InstalledAppsStore extends ComponentStore<InstalledAppsState> imple
) {
super(initialState);
this.initialize();
this.getStats();
}

readonly initialize = this.effect((triggers$: Observable<void>) => {
Expand All @@ -61,19 +63,30 @@ export class InstalledAppsStore extends ComponentStore<InstalledAppsState> 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({
isLoading: false,
});
}

private loadInstalledApps(): Observable<unknown> {
private loadInstalledApps(): Observable<App[]> {
return this.dockerStore.isLoading$.pipe(
withLatestFrom(this.dockerStore.isDockerStarted$),
filter(([isLoading, isDockerStarted]) => !isLoading && isDockerStarted !== null),
switchMap(([, isDockerStarted]) => {
this.appsStats.subscribeToUpdates();
this.subscribeToInstalledAppsUpdates();

if (!isDockerStarted) {
Expand Down

0 comments on commit e64b7af

Please sign in to comment.