diff --git a/frontend/src/pages/ChatBot.jsx b/frontend/src/pages/ChatBot.jsx index 62a5dee9..181d5517 100644 --- a/frontend/src/pages/ChatBot.jsx +++ b/frontend/src/pages/ChatBot.jsx @@ -8,7 +8,8 @@ function ChatBot() { const [chatHistory, setChatHistory] = useState([]); const chatHistoryRef = useRef(null); const [loading, setLoading] = useState(false); - const [showLoadingModal, setShowLoadingModal] = useState(true); // Changed to show modal + const [showLoadingModal, setShowLoadingModal] = useState(false); + const [firstMessageSent, setFirstMessageSent] = useState(false); // Track if first message is sent const loadChatHistory = () => { const savedChatHistory = localStorage.getItem('chatHistory'); @@ -25,10 +26,17 @@ function ChatBot() { if (userPrompt.trim() === '') return; setLoading(true); + const updatedHistory = [...chatHistory, { role: 'user', content: userPrompt }]; setChatHistory(updatedHistory); saveChatHistory(updatedHistory); + // Show the loading modal only for the first message + if (!firstMessageSent) { + setShowLoadingModal(true); + setFirstMessageSent(true); + } + try { const response = await fetch('https://agrotech-chatbot.onrender.com/AgroTech-ChatBot', { method: 'POST', @@ -90,18 +98,18 @@ function ChatBot() {

AgroTech AI ChatBot

{/* Modal for loading message */} - {showLoadingModal && (
-
- -

Your AI Agent is on the way...

- Loading... -

The model may take some 1 - 2 minutes to load. Please be patient!

-
-
- )} - + {showLoadingModal && ( +
+
+ +

Your AI Agent is on the way...

+ Loading... +

The model may take some 1 - 2 minutes to load. Please be patient!

+
+
+ )}