Skip to content

Commit 194bb5e

Browse files
committed
🐛reset selected app after uninstalling same app
1 parent 4136a5b commit 194bb5e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

controlpanel/cad/src/app/services/app-list.service.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { BehaviorSubject, lastValueFrom } from 'rxjs';
33
import { AppListApiService } from './api/app-list-api.service';
44
import { ProtectedApp } from '../models/protected-app';
55
import { ApiResponse } from '../models/api-response';
6+
import { GlobalStateService } from './global-state.service';
67

78
@Injectable({
89
providedIn: 'root'
@@ -12,7 +13,7 @@ export class AppListService {
1213
private applistSubject = new BehaviorSubject<ProtectedApp[]>([]);
1314
applist$ = this.applistSubject.asObservable();
1415

15-
constructor(private applistApi: AppListApiService) { }
16+
constructor(private applistApi: AppListApiService, private globalState: GlobalStateService) { }
1617

1718
get applist(): ProtectedApp[] {
1819
return this.applistSubject?.value || [];
@@ -24,7 +25,13 @@ export class AppListService {
2425
async getAppList(): Promise<ApiResponse> {
2526
try {
2627
const apiResponse = await lastValueFrom(this.applistApi.getAppList());
27-
if (apiResponse.type == 'success') this.applist = apiResponse.data as ProtectedApp[];
28+
if (apiResponse.type == 'success') {
29+
this.applist = apiResponse.data as ProtectedApp[];
30+
if (!this.applist.find(app => app.id == this.globalState.selectedApp.id)) {
31+
const defaultApp = this.applist.find(app => app.namespace == 'default' && app.application == 'default');
32+
this.globalState.selectedApp = defaultApp || this.applist[0];
33+
}
34+
}
2835
return apiResponse;
2936
} catch (error) {
3037
return { type: 'error', message: 'Error when fetching app list' };

0 commit comments

Comments
 (0)