11import { HttpClient } from '@angular/common/http' ;
2- import { Component , input , output } from '@angular/core' ;
2+ import { Component , inject , input , output , signal } from '@angular/core' ;
33import { FormsModule } from '@angular/forms' ;
44import { firstValueFrom } from 'rxjs' ;
55import {
@@ -20,17 +20,19 @@ interface Model {
2020 styleUrl : './ai-assistant.scss' ,
2121 imports : [ FormsModule , MessageSpinner ] ,
2222 host : {
23- '[class.expanded]' : 'isExpanded' ,
23+ '[class.expanded]' : 'isExpanded() ' ,
2424 } ,
2525} )
2626export class AiAssistant {
2727 readonly reportGroupId = input . required < string > ( ) ;
2828 readonly close = output ( ) ;
2929
3030 protected messages : AiChatMessage [ ] = [ ] ;
31- protected userInput = '' ;
32- protected isLoading = false ;
33- protected isExpanded = false ;
31+ protected userInput = signal ( '' ) ;
32+ protected isLoading = signal ( false ) ;
33+ protected isExpanded = signal ( false ) ;
34+
35+ private readonly http = inject ( HttpClient ) ;
3436
3537 protected readonly models : Model [ ] = [
3638 { id : 'gemini-2.5-flash' , name : 'Gemini 2.5 Flash' } ,
@@ -39,23 +41,21 @@ export class AiAssistant {
3941 ] ;
4042 protected selectedModel = this . models [ 0 ] . id ;
4143
42- constructor ( private readonly http : HttpClient ) { }
43-
4444 protected toggleExpanded ( ) : void {
45- this . isExpanded = ! this . isExpanded ;
45+ this . isExpanded . set ( ! this . isExpanded ( ) ) ;
4646 }
4747
4848 async send ( ) : Promise < void > {
49- if ( ! this . userInput . trim ( ) || this . isLoading ) {
49+ if ( ! this . userInput ( ) . trim ( ) || this . isLoading ( ) ) {
5050 return ;
5151 }
5252
5353 const pastMessages = this . messages . slice ( ) ;
5454
55- this . messages . push ( { role : 'user' , text : this . userInput } ) ;
56- const prompt = this . userInput ;
57- this . userInput = '' ;
58- this . isLoading = true ;
55+ this . messages . push ( { role : 'user' , text : this . userInput ( ) } ) ;
56+ const prompt = this . userInput ( ) ;
57+ this . userInput . set ( '' ) ;
58+ this . isLoading . set ( true ) ;
5959
6060 const payload : AiChatRequest = {
6161 prompt,
@@ -75,7 +75,7 @@ export class AiAssistant {
7575 text : 'Sorry, I failed to get a response. Please try again.' ,
7676 } ) ;
7777 } finally {
78- this . isLoading = false ;
78+ this . isLoading . set ( false ) ;
7979 }
8080 }
8181}
0 commit comments