Skip to content
Snippets Groups Projects
Commit 2ba92998 authored by Alex Yang's avatar Alex Yang Committed by GitHub
Browse files

feat: add loading indicator (#203)

parent ff72dea4
No related branches found
No related tags found
No related merge requests found
import { useEffect, useRef } from "react"; import { useEffect, useRef } from "react";
import { Loader2 } from "lucide-react";
import ChatActions from "./chat-actions"; import ChatActions from "./chat-actions";
import ChatMessage from "./chat-message"; import ChatMessage from "./chat-message";
...@@ -24,6 +25,11 @@ export default function ChatMessages( ...@@ -24,6 +25,11 @@ export default function ChatMessages(
props.reload && !props.isLoading && isLastMessageFromAssistant; props.reload && !props.isLoading && isLastMessageFromAssistant;
const showStop = props.stop && props.isLoading; const showStop = props.stop && props.isLoading;
// `isPending` indicate
// that stream response is not yet received from the server,
// so we show a loading indicator to give a better UX.
const isPending = props.isLoading && !isLastMessageFromAssistant;
useEffect(() => { useEffect(() => {
scrollToBottom(); scrollToBottom();
}, [messageLength, lastMessage]); }, [messageLength, lastMessage]);
...@@ -37,6 +43,13 @@ export default function ChatMessages( ...@@ -37,6 +43,13 @@ export default function ChatMessages(
{props.messages.map((m) => ( {props.messages.map((m) => (
<ChatMessage key={m.id} {...m} /> <ChatMessage key={m.id} {...m} />
))} ))}
{isPending && (
<div
className='flex justify-center items-center pt-10'
>
<Loader2 className="h-4 w-4 animate-spin"/>
</div>
)}
</div> </div>
<div className="flex justify-end py-4"> <div className="flex justify-end py-4">
<ChatActions <ChatActions
......
...@@ -26,4 +26,4 @@ ...@@ -26,4 +26,4 @@
"tailwindcss": "^3.3", "tailwindcss": "^3.3",
"typescript": "^5" "typescript": "^5"
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment