1
0
Fork 0
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:
Zach Gollwitzer 2025-03-12 14:06:42 -04:00
parent d1b83541c1
commit 3f9858a67f
9 changed files with 127 additions and 13 deletions

View 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 = "";
}
}