mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
Add streaming chat
This commit is contained in:
parent
d1b83541c1
commit
3f9858a67f
9 changed files with 127 additions and 13 deletions
32
app/javascript/controllers/chat_controller.js
Normal file
32
app/javascript/controllers/chat_controller.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { Controller } from "@hotwired/stimulus";
|
||||
|
||||
// Connects to data-controller="chat-scroll"
|
||||
export default class extends Controller {
|
||||
static targets = ["form", "messages"];
|
||||
|
||||
connect() {
|
||||
this.scrollToBottom();
|
||||
|
||||
this.observer = new MutationObserver(() => {
|
||||
this.scrollToBottom();
|
||||
this.clearInput();
|
||||
});
|
||||
|
||||
this.observer.observe(this.messagesTarget, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
});
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
this.observer.disconnect();
|
||||
}
|
||||
|
||||
scrollToBottom() {
|
||||
this.messagesTarget.scrollTop = this.messagesTarget.scrollHeight;
|
||||
}
|
||||
|
||||
clearInput() {
|
||||
this.formTarget.querySelector("textarea").value = "";
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue