feat: scroll to new message

This commit is contained in:
Cat Flynn 2025-05-02 17:18:02 +01:00
parent e525120a15
commit a07c269f15

13
main.js
View File

@ -23,6 +23,15 @@ class Conversation {
this.messages = initialMessages; this.messages = initialMessages;
} }
addMessage(message) {
this.messages.push(message);
this.render();
var elements = document.getElementById("messages").children;
var lastElement = elements[elements.length - 1];
lastElement.scrollIntoView();
}
// for the user to send their own messages // for the user to send their own messages
sendUserMessage(text) { sendUserMessage(text) {
@ -74,7 +83,7 @@ class Conversation {
messageText = json.message; messageText = json.message;
} }
this.messages.push(new AgentMessage(messageText)); this.addMessage(new AgentMessage(messageText));
this.render(); this.render();
}) })
.catch(error => { .catch(error => {
@ -91,7 +100,7 @@ class Conversation {
// this.render(); // this.render();
//}, 5000); //}, 5000);
}, 1000); }, 1000);
this.messages.push(message); this.addMessage(message);
} }
// update the current HTML based on messages // update the current HTML based on messages