From 558090c56deb1578d34b45afffdbf870688166d5 Mon Sep 17 00:00:00 2001 From: RehanY147 Date: Fri, 1 Nov 2024 15:56:26 +0500 Subject: [PATCH] NAS-131913: Fix the sequence of state updates (#10959) --- src/app/pages/apps/store/docker.store.ts | 5 ++++- .../apps/store/installed-apps-store.service.ts | 13 +++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/app/pages/apps/store/docker.store.ts b/src/app/pages/apps/store/docker.store.ts index 34543444fb3..c2fcafd7b07 100644 --- a/src/app/pages/apps/store/docker.store.ts +++ b/src/app/pages/apps/store/docker.store.ts @@ -39,7 +39,10 @@ export class DockerStore extends ComponentStore { readonly selectedPool$ = this.select((state) => state.dockerConfig?.pool || null); readonly nvidiaDriversInstalled$ = this.select((state) => state.nvidiaDriversInstalled); readonly lacksNvidiaDrivers$ = this.select((state) => state.lacksNvidiaDrivers); - readonly isDockerStarted$ = this.select((state) => DockerStatus.Running === state.statusData.status); + readonly isDockerStarted$ = this.select((state) => { + return state.statusData.status == null ? null : DockerStatus.Running === state.statusData.status; + }); + readonly status$ = this.select((state) => state.statusData.status); readonly statusDescription$ = this.select((state) => state.statusData.description); 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 e32e686a703..f27d0807e9d 100644 --- a/src/app/pages/apps/store/installed-apps-store.service.ts +++ b/src/app/pages/apps/store/installed-apps-store.service.ts @@ -3,8 +3,7 @@ import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { ComponentStore } from '@ngrx/component-store'; import { EMPTY, - Observable, Subscription, catchError, delay, filter, of, repeat, switchMap, tap, - withLatestFrom, + Observable, Subscription, catchError, combineLatest, delay, filter, of, repeat, switchMap, tap, } from 'rxjs'; import { IncomingApiMessageType } from 'app/enums/api-message-type.enum'; import { tapOnce } from 'app/helpers/operators/tap-once.operator'; @@ -92,18 +91,20 @@ export class InstalledAppsStore extends ComponentStore imple } private loadInstalledApps(): Observable { - return this.dockerStore.isLoading$.pipe( - withLatestFrom(this.dockerStore.isDockerStarted$), + return combineLatest([ + this.dockerStore.isLoading$, + this.dockerStore.isDockerStarted$, + ]).pipe( filter(([isLoading, isDockerStarted]) => !isLoading && isDockerStarted !== null), + tap(() => this.patchState({ isLoading: true })), switchMap(([, isDockerStarted]) => { - this.subscribeToInstalledAppsUpdates(); - if (!isDockerStarted) { return of([]); } return this.appsService.getAllApps().pipe( tap((installedApps) => this.patchState({ installedApps })), + tap(() => this.subscribeToInstalledAppsUpdates()), repeat({ // TODO: NAS-131676. Remove this workaround after the bug is fixed. delay: () => this.appsService.getInstalledAppsUpdates().pipe(