From 8e500c1274aaee87c283a2f8a303ea196d4451c6 Mon Sep 17 00:00:00 2001 From: Harish Mohan Raj Date: Tue, 14 Nov 2023 19:27:58 +0530 Subject: [PATCH] Add loader --- src/client/ChatPage.jsx | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/client/ChatPage.jsx b/src/client/ChatPage.jsx index f794fc9..4b4fdc0 100644 --- a/src/client/ChatPage.jsx +++ b/src/client/ChatPage.jsx @@ -3,7 +3,7 @@ import { useQuery } from '@wasp/queries' import getChats from '@wasp/queries/getChats' import getConversations from '@wasp/queries/getConversations' import logout from '@wasp/auth/logout'; -import { useState, Dispatch, SetStateAction } from 'react'; +import { useState, useEffect, useRef } from 'react'; // import { Chat, Conversation } from '@wasp/entities' import { Link } from '@wasp/router' import Markdown from 'react-markdown' @@ -37,6 +37,14 @@ const ChatsList = ({ chats }) => { ) } +const Loader = () => { + return ( +
+
+
+ ) +} + const ConversationsList = ({ conversations }) => { if (!conversations?.length) return
No conversations
@@ -72,6 +80,7 @@ export default function ChatPage(props) { const [isLoading, setIsLoading] = useState(false); const [chatConversations, setChatConversations] = useState([{}]); const [conversationId, setConversationId] = useState(null); + const chatContainerRef = useRef(null); // const [chatId, setChatId] = useState(null); const { data: chats, isLoading: isLoadingChats } = useQuery(getChats) @@ -85,9 +94,17 @@ export default function ChatPage(props) { // } // setChatId(props.match.params.id) // console.log(`chatId: ${chatId}`) + + useEffect(() => { + if (chatContainerRef.current) { + chatContainerRef.current.scrollTop = chatContainerRef.current.scrollHeight; + } + }, [conversations]); const history = useHistory(); + + const chatContainerClass = `flex h-full flex-col items-center justify-between pb-24 overflow-y-auto bg-captn-light-blue ${isLoading ? 'opacity-40' : 'opacity-100'}` const handleClick = async (event) => { event.preventDefault() @@ -117,10 +134,12 @@ export default function ChatPage(props) { } await updateConversation(payload) // 2. call backend python server to get agent response + setIsLoading(true) const response = await getAgentResponse({ message: userQuery, conv_id: payload.conversation_id, }) + setIsLoading(false) // 3. add agent response as new conversation in the table const openAIPayload = { conversation_id: conversations.id, @@ -159,9 +178,10 @@ export default function ChatPage(props) {
-
+
{conversations && }
+ {isLoading && } {props.match.params.id ? (