11import { HttpClient } from '@angular/common/http' ;
2- import { Component , input , output } from '@angular/core' ;
2+ import {
3+ Component ,
4+ ElementRef ,
5+ inject ,
6+ Injector ,
7+ input ,
8+ output ,
9+ signal ,
10+ viewChild ,
11+ } from '@angular/core' ;
312import { FormsModule } from '@angular/forms' ;
413import { firstValueFrom } from 'rxjs' ;
514import {
@@ -20,17 +29,20 @@ interface Model {
2029 styleUrl : './ai-assistant.scss' ,
2130 imports : [ FormsModule , MessageSpinner ] ,
2231 host : {
23- '[class.expanded]' : 'isExpanded' ,
32+ '[class.expanded]' : 'isExpanded() ' ,
2433 } ,
2534} )
2635export class AiAssistant {
2736 readonly reportGroupId = input . required < string > ( ) ;
2837 readonly close = output ( ) ;
2938
3039 protected messages : AiChatMessage [ ] = [ ] ;
31- protected userInput = '' ;
32- protected isLoading = false ;
33- protected isExpanded = false ;
40+ protected userInput = signal ( '' ) ;
41+ protected isLoading = signal ( false ) ;
42+ protected isExpanded = signal ( false ) ;
43+ protected messagesContainer = viewChild ( 'messagesContainer' , { read : ElementRef } ) ;
44+
45+ private readonly http = inject ( HttpClient ) ;
3446
3547 protected readonly models : Model [ ] = [
3648 { id : 'gemini-2.5-flash' , name : 'Gemini 2.5 Flash' } ,
@@ -39,23 +51,21 @@ export class AiAssistant {
3951 ] ;
4052 protected selectedModel = this . models [ 0 ] . id ;
4153
42- constructor ( private readonly http : HttpClient ) { }
43-
4454 protected toggleExpanded ( ) : void {
45- this . isExpanded = ! this . isExpanded ;
55+ this . isExpanded . set ( ! this . isExpanded ( ) ) ;
4656 }
4757
4858 async send ( ) : Promise < void > {
49- if ( ! this . userInput . trim ( ) || this . isLoading ) {
59+ if ( ! this . userInput ( ) . trim ( ) || this . isLoading ( ) ) {
5060 return ;
5161 }
5262
5363 const pastMessages = this . messages . slice ( ) ;
5464
55- this . messages . push ( { role : 'user' , text : this . userInput } ) ;
56- const prompt = this . userInput ;
57- this . userInput = '' ;
58- this . isLoading = true ;
65+ this . messages . push ( { role : 'user' , text : this . userInput ( ) } ) ;
66+ const prompt = this . userInput ( ) ;
67+ this . userInput . set ( '' ) ;
68+ this . isLoading . set ( true ) ;
5969
6070 const payload : AiChatRequest = {
6171 prompt,
@@ -75,7 +85,7 @@ export class AiAssistant {
7585 text : 'Sorry, I failed to get a response. Please try again.' ,
7686 } ) ;
7787 } finally {
78- this . isLoading = false ;
88+ this . isLoading . set ( false ) ;
7989 }
8090 }
8191}
0 commit comments