Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3l Solution 1 #4

Open
wants to merge 1 commit into
base: 3l
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions 2-copy-of-code/lesson-03/chatbot.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
}

async function sendMessage() {
// We can put this at the top of the function or
// after the first setChatMessages(). Both work.
setInputText('');

const newChatMessages = [
...chatMessages,
{
Expand All @@ -30,7 +34,17 @@
}
];

setChatMessages(newChatMessages);
setChatMessages([
...newChatMessages,
// This creates a temporary Loading... message.
// Because we don't save this message in newChatMessages,
// it will be remove later, when we add the response.
{
message: 'Loading...',
sender: 'robot',
id: crypto.randomUUID()
}
]);

const response = await Chatbot.getResponseAsync(inputText);
setChatMessages([
Expand All @@ -41,8 +55,6 @@
id: crypto.randomUUID()
}
]);

setInputText('');
}

function handleKeyDown(event) {
Expand Down