Skip to content

Commit

Permalink
Submit chat messages on return key press (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
rorywhite200 authored and joelostblom committed Sep 13, 2024
1 parent 278bd99 commit a5858e9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions textbook/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function createChatInterface({

chatDisplay.innerHTML += createChatMessageHTML(firstMessage, true);

submitButton.onclick = async () => {
async function handleSubmit() {
const prompt = userInput.value;
if (prompt.trim() === '') return;
messageCount++;
Expand All @@ -90,7 +90,10 @@ export function createChatInterface({
chatDisplay.innerHTML += createChatMessageHTML("Error: " + error.message, true);
}
chatDisplay.scrollTop = chatDisplay.scrollHeight;
};
}

submitButton.onclick = handleSubmit;
userInput.addEventListener('keypress', e => e.key === 'Enter' && !e.shiftKey && (e.preventDefault(), handleSubmit()));

chatDisplay.scrollTop = chatDisplay.scrollHeight;
return container;
Expand Down

0 comments on commit a5858e9

Please sign in to comment.