From ef69e3b54dc4ad80d05b3684a8efbc717be1e739 Mon Sep 17 00:00:00 2001 From: Nikki Yong <75350534+yongkfn@users.noreply.github.com> Date: Fri, 1 Mar 2024 21:14:03 +0800 Subject: [PATCH] added loading spinner Added a spinner component whenever waiting for a query response, so that users know something is still happening --- .../app/components/ui/chat/chat-actions.tsx | 2 +- .../app/components/ui/chat/chat-messages.tsx | 78 ++++++++++++++++++- 2 files changed, 76 insertions(+), 4 deletions(-) diff --git a/frontend/app/components/ui/chat/chat-actions.tsx b/frontend/app/components/ui/chat/chat-actions.tsx index 6f983c6..b2771bb 100644 --- a/frontend/app/components/ui/chat/chat-actions.tsx +++ b/frontend/app/components/ui/chat/chat-actions.tsx @@ -7,7 +7,7 @@ export default function ChatActions( props: Pick & { showReload?: boolean; showStop?: boolean; - }, + } ) { return (
diff --git a/frontend/app/components/ui/chat/chat-messages.tsx b/frontend/app/components/ui/chat/chat-messages.tsx index a330dae..200c599 100644 --- a/frontend/app/components/ui/chat/chat-messages.tsx +++ b/frontend/app/components/ui/chat/chat-messages.tsx @@ -1,11 +1,12 @@ -import { useEffect, useRef } from "react"; +import { useEffect, useRef, useState, CSSProperties } from "react"; +import PuffLoader from "react-spinners/PuffLoader"; import ChatActions from "./chat-actions"; import ChatMessage from "./chat-message"; import { ChatHandler } from "./chat.interface"; export default function ChatMessages( - props: Pick, + props: Pick ) { const scrollableChatContainerRef = useRef(null); const messageLength = props.messages.length; @@ -28,8 +29,27 @@ export default function ChatMessages( scrollToBottom(); }, [messageLength, lastMessage]); + // State to manage the visibility of the ellipsis + const [showEllipsis, setShowEllipsis] = useState(true); + + useEffect(() => { + // Toggle the visibility of the ellipsis every second + const interval = setInterval(() => { + setShowEllipsis((prev) => !prev); + }, 1000); + + return () => clearInterval(interval); + }, []); // Empty dependency array to run only once on component mount + return ( -
+
+ {props.isLoading && ( +
+

+ +

+
+ )}
); } + +// import { useEffect, useRef } from "react"; + +// import ChatActions from "./chat-actions"; +// import ChatMessage from "./chat-message"; +// import { ChatHandler } from "./chat.interface"; + +// export default function ChatMessages( +// props: Pick, +// ) { +// const scrollableChatContainerRef = useRef(null); +// const messageLength = props.messages.length; +// const lastMessage = props.messages[messageLength - 1]; + +// const scrollToBottom = () => { +// if (scrollableChatContainerRef.current) { +// scrollableChatContainerRef.current.scrollTop = +// scrollableChatContainerRef.current.scrollHeight; +// } +// }; + +// const isLastMessageFromAssistant = +// messageLength > 0 && lastMessage?.role !== "user"; +// const showReload = +// props.reload && !props.isLoading && isLastMessageFromAssistant; +// const showStop = props.stop && props.isLoading; + +// useEffect(() => { +// scrollToBottom(); +// }, [messageLength, lastMessage]); + +// return ( +//
+//
+// {props.messages.map((m) => ( +// +// ))} +//
+//
+// +//
+//
+// ); +// }