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

4k Solution #11

Open
wants to merge 1 commit into
base: 4k
Choose a base branch
from
Open
Show file tree
Hide file tree
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
29 changes: 24 additions & 5 deletions 2-copy-of-code/lesson-04/chatbot.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
color: rgb(120, 120, 120);
text-align: center;
}

.loading-spinner {
height: 40px;
margin: -15px;
}
</style>
</head>
<body>
Expand All @@ -100,7 +105,13 @@
setInputText(event.target.value);
}

function sendMessage() {
async function sendMessage() {
// Clear the textbox at the top now because the Chatbot
// will take some time to load the response. We want
// to clear the textbox immediately rather waiting
// for the Chatbot to finish loading.
setInputText('');

const newChatMessages = [
...chatMessages,
{
Expand All @@ -110,9 +121,19 @@
}
];

setChatMessages(newChatMessages);
setChatMessages([
...newChatMessages,
// This creates a temporary Loading... message.
// Because we don't save this message in newChatMessages,
// it will be removed later, when we add the response.
{
message: <img src="loading-spinner.gif" className="loading-spinner" />,
sender: 'robot',
id: crypto.randomUUID()
}
]);

const response = Chatbot.getResponse(inputText);
const response = await Chatbot.getResponseAsync(inputText);
setChatMessages([
...newChatMessages,
{
Expand All @@ -121,8 +142,6 @@
id: crypto.randomUUID()
}
]);

setInputText('');
}

return (
Expand Down
Binary file added 2-copy-of-code/lesson-04/loading-spinner.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.