Skip to content

Commit

Permalink
NAS-131913: Fix the sequence of state updates (#10959)
Browse files Browse the repository at this point in the history
  • Loading branch information
RehanY147 authored Nov 1, 2024
1 parent 4fb8c4a commit 558090c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/app/pages/apps/store/docker.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export class DockerStore extends ComponentStore<DockerConfigState> {
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);

Expand Down
13 changes: 7 additions & 6 deletions src/app/pages/apps/store/installed-apps-store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -92,18 +91,20 @@ export class InstalledAppsStore extends ComponentStore<InstalledAppsState> imple
}

private loadInstalledApps(): Observable<App[]> {
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(
Expand Down

0 comments on commit 558090c

Please sign in to comment.