Browse Source

Fixed the docked AI panel not appearing after a user switch without a page reload (e.g. Login as from the system administrator): AI availability now follows the auth state, and the panel is mounted again when its host comes back

pull/16882/head
Igor Kulikov 1 day ago
parent
commit
284907c300
  1. 2
      ui-ngx/src/app/modules/home/home.component.html
  2. 21
      ui-ngx/src/app/modules/home/home.component.ts

2
ui-ngx/src/app/modules/home/home.component.html

@ -118,7 +118,7 @@
</div>
</div>
</div>
@if (aiAvailable) {
@if (aiAvailable()) {
<ng-container #aiPanelHost></ng-container>
}
</mat-sidenav-content>

21
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<AppState>).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);
}

Loading…
Cancel
Save