Wait for AI response before letting user send another message in GUI
This commit is contained in:
@@ -17,6 +17,7 @@ function displayMessage(message, sender) {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const chatForm = document.getElementById('chatForm');
|
||||
const promptInput = document.getElementById('promptInput');
|
||||
const sendButton = document.getElementById('sendButton');
|
||||
|
||||
if (chatForm && promptInput) {
|
||||
chatForm.addEventListener('submit', async (event) => {
|
||||
@@ -24,6 +25,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const userInput = promptInput.value;
|
||||
promptInput.value = '';
|
||||
|
||||
sendButton.disabled = true;
|
||||
promptInput.disabled = true;
|
||||
|
||||
displayMessage(userInput, 'user');
|
||||
|
||||
try {
|
||||
@@ -33,9 +37,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
} catch (error) {
|
||||
console.error(`Error sending prompt: ${error.message}`);
|
||||
displayMessage(`Error: ${error.message}`, 'assistant');
|
||||
} finally {
|
||||
sendButton.disabled = false;
|
||||
promptInput.disabled = false;
|
||||
promptInput.focus();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.error('chatForm or promptInput elements not found!');
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user