diff --git a/ui-ngx/src/app/modules/home/home.component.html b/ui-ngx/src/app/modules/home/home.component.html
index e4a2d3177a..c7626e2a10 100644
--- a/ui-ngx/src/app/modules/home/home.component.html
+++ b/ui-ngx/src/app/modules/home/home.component.html
@@ -118,7 +118,7 @@
- @if (aiAvailable) {
+ @if (aiAvailable()) {
}
diff --git a/ui-ngx/src/app/modules/home/home.component.ts b/ui-ngx/src/app/modules/home/home.component.ts
index 0bee0037c9..8577aa4968 100644
--- a/ui-ngx/src/app/modules/home/home.component.ts
+++ b/ui-ngx/src/app/modules/home/home.component.ts
@@ -4,12 +4,13 @@
import { AfterViewInit, Component, computed, createNgModule, ElementRef, Inject, Injector, OnDestroy, OnInit, Renderer2, signal, ViewChild, ViewContainerRef, inject } from '@angular/core';
import { combineLatest, Observable, skip, startWith, Subject } from 'rxjs';
import { select, Store } from '@ngrx/store';
+import { toSignal } from '@angular/core/rxjs-interop';
import { debounceTime, distinctUntilChanged, map, share, take, takeUntil } from 'rxjs/operators';
import { BreakpointObserver, BreakpointState } from '@angular/cdk/layout';
import { PageComponent } from '@shared/components/page.component';
import { AppState } from '@core/core.state';
-import { getCurrentAuthState, selectUserSettingsProperty } from '@core/auth/auth.selectors';
+import { getCurrentAuthState, selectAuth, selectUserSettingsProperty } from '@core/auth/auth.selectors';
import { MediaBreakpoints } from '@shared/models/constants';
import screenfull from 'screenfull';
import { MatSidenav } from '@angular/material/sidenav';
@@ -74,17 +75,27 @@ export class HomeComponent extends PageComponent implements AfterViewInit, OnIni
private tourService = inject(TourService);
- readonly aiAvailable = this.tourService.aiAvailable();
+ readonly aiAvailable = toSignal(inject(Store).select(selectAuth).pipe(
+ map(() => this.tourService.aiAvailable()),
+ distinctUntilChanged()
+ ), {initialValue: this.tourService.aiAvailable()});
readonly aiPanelLoaded = signal(false);
private injector = inject(Injector);
- @ViewChild('aiPanelHost', {read: ViewContainerRef}) set aiPanelHost(host: ViewContainerRef) {
- if (host && !this.aiPanelLoaded()) {
+ private panelHost: ViewContainerRef | undefined;
+
+ @ViewChild('aiPanelHost', {read: ViewContainerRef}) set aiPanelHost(host: ViewContainerRef | undefined) {
+ this.panelHost = host;
+ if (!host) {
+ this.aiPanelLoaded.set(false);
+ return;
+ }
+ if (!this.aiPanelLoaded()) {
Promise.all([import('@home/components/ai/ai.module'), import('@home/components/ai/ai-assistant-panel.component')])
.then(([{AiModule}, {AiAssistantPanelComponent}]) => {
- if (!this.aiPanelLoaded()) {
+ if (this.panelHost === host && !this.aiPanelLoaded()) {
host.createComponent(AiAssistantPanelComponent, {ngModuleRef: createNgModule(AiModule, this.injector)});
this.aiPanelLoaded.set(true);
}