diff --git a/src-ui/src/app/components/chat/chat/chat.component.html b/src-ui/src/app/components/chat/chat/chat.component.html index 54753c88f..f0b61b805 100644 --- a/src-ui/src/app/components/chat/chat/chat.component.html +++ b/src-ui/src/app/components/chat/chat/chat.component.html @@ -20,8 +20,9 @@
- @ViewChild('inputField') inputField!: ElementRef + @ViewChild('chatInput') chatInput!: ElementRef private typewriterBuffer: string[] = [] private typewriterActive = false - constructor(private chatService: ChatService) {} + public get placeholder(): string { + return this.documentId + ? $localize`Ask a question about this document...` + : $localize`Ask a question about a document...` + } + + constructor( + private chatService: ChatService, + private router: Router + ) {} + + ngOnInit(): void { + this.updateDocumentId(this.router.url) + this.router.events + .pipe( + filter((event) => event instanceof NavigationEnd), + map(() => this.router.url) + ) + .subscribe((url) => { + this.updateDocumentId(url) + }) + } + + private updateDocumentId(url: string): void { + const docIdRe = url.match(/^\/documents\/(\d+)/) + this.documentId = docIdRe ? +docIdRe[1] : undefined + } sendMessage(): void { if (!this.input.trim()) return const userMessage: ChatMessage = { role: 'user', content: this.input } this.messages.push(userMessage) + this.scrollToBottom() const assistantMessage: ChatMessage = { role: 'assistant', @@ -98,7 +128,7 @@ export class ChatComponent { public onOpenChange(open: boolean): void { if (open) { setTimeout(() => { - this.inputField.nativeElement.focus() + this.chatInput.nativeElement.focus() }, 10) } }