diff --git a/frontend/index.html b/frontend/index.html index 88d8574..10d9189 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -26,13 +26,13 @@ left: 0; pointer-events: none; z-index: 99999999; - /* Stays on top of all elements */ + } - /* Chatbot styles */ + .chatbot-container { position: relative; - bottom: 20px; /* Adjust as needed */ + bottom: 20px; right: 20px; z-index: 100; } @@ -56,7 +56,7 @@ .chatbox { display: none; position: fixed; - bottom: 90px; /* Position above the bottom of the viewport */ + bottom: 90px; right: 20px; width: 300px; background-color: #f9f9f9; @@ -215,9 +215,9 @@

Saarthi

userMessages.forEach((message) => { const cleanedMessage = message.trim().toLowerCase().replace(/[?,.!]/g, ''); // Remove punctuation if (cleanedMessage in responses) { - chatOutput.innerHTML += `

${responses[cleanedMessage]}

`; + chatOutput.innerHTML +=

${responses[cleanedMessage]}

; } else if (cleanedMessage) { - chatOutput.innerHTML += `

I'm sorry, I don't have an answer for that.

`; + chatOutput.innerHTML +=

I'm sorry, I don't have an answer for that.

; } }); @@ -306,4 +306,4 @@

Saarthi

animateCircles(); - + \ No newline at end of file diff --git a/frontend/src/Pages/Herosection.jsx b/frontend/src/Pages/Herosection.jsx index 7e70503..1e32278 100644 --- a/frontend/src/Pages/Herosection.jsx +++ b/frontend/src/Pages/Herosection.jsx @@ -14,7 +14,7 @@ import HamburgerMenu from './hamburger'; import contributor from './contributor'; import contributorsvg from '../assets/svg/contributor.svg'; import chatbotsvg from '../assets/svg/chatbot.svg'; - +import Chatbot from '../components/chatbot'; const Herosection = () => { const navigate = useNavigate(); @@ -45,9 +45,7 @@ const Herosection = () => { const ContributorCLick = () => { navigate('/contributors'); // Navigates to the login page } - const ChatbotCLick = () => { - navigate('/chatbot'); // Navigates to the login page - } + return ( <> @@ -99,13 +97,11 @@ const Herosection = () => {

Contributors

-
- chatbot -

Saarthi

+ ); }; -export default Herosection; +export default Herosection; \ No newline at end of file diff --git a/frontend/src/components/chatbot.css b/frontend/src/components/chatbot.css new file mode 100644 index 0000000..55dad07 --- /dev/null +++ b/frontend/src/components/chatbot.css @@ -0,0 +1,86 @@ +.chatbot-container { + position: fixed; + display: flex; + flex-direction: column; + right: 20px; + z-index: 1000; + } + + .chatbot { + --tw-bg-opacity: 1; + background-color: rgb(191 219 254 / var(--tw-bg-opacity)); + border-radius: 50%; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + width: 60px; + height: 60px; + cursor: pointer; + display: flex; + justify-content: center; + align-items: center; + } + + .chatbot img { + width: 40px; + height: 40px; + } + + .chatbox { + background-color: #f1f1f1; + border: 1px solid #ccc; + border-radius: 10px; + width: 300px; + position: absolute; + bottom: 70px; + right: 0; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + display: flex; + flex-direction: column; + padding: 15px; + } + + .chatbox h3 { + margin: 0; + padding-bottom: 10px; + text-align: center; + } + + .chat-output { + flex-grow: 1; + background-color: #fff; + border-radius: 5px; + padding: 10px; + margin-bottom: 10px; + overflow-y: auto; + max-height: 200px; + } + + .chat-output p { + margin: 5px 0; + padding: 5px 10px; + background-color: #e0e0e0; + border-radius: 5px; + } + + #chatInput { + resize: none; + padding: 10px; + border: 1px solid #ccc; + border-radius: 5px; + margin-bottom: 10px; + } + + #sendMessage { + --tw-bg-opacity: 1; + background-color: rgb(59 130 246 / var(--tw-bg-opacity)); + color: white; + border: none; + padding: 10px; + border-radius: 5px; + cursor: pointer; + } + + #sendMessage:hover { + --tw-bg-opacity: 2; + background-color: rgb(28 97 211 / var(--tw-bg-opacity)); + + } \ No newline at end of file diff --git a/frontend/src/components/chatbot.jsx b/frontend/src/components/chatbot.jsx index fb7aa7c..2527f00 100644 --- a/frontend/src/components/chatbot.jsx +++ b/frontend/src/components/chatbot.jsx @@ -1,9 +1,79 @@ -import React from 'react' +import React, { useState } from 'react'; +import './chatbot.css'; // Import the CSS file +import chatbotsvg from '../assets/svg/chatbot.svg'; // Import the chatbot icon + +const Chatbot = () => { + const [chatboxOpen, setChatboxOpen] = useState(false); + const [chatInput, setChatInput] = useState(''); + const [chatOutput, setChatOutput] = useState([]); + const [welcomeMessageDisplayed, setWelcomeMessageDisplayed] = useState(false); + + const responses = { + "can you help me navigate to platform 5": "You can easily navigate to Platform 5 using Navigation in the menu. Anything else I can help you with?", + "yes where can i find luggage storage facilities": "You can check the availability of cloakrooms in booking and book the same.", + "hello": "Hi there! How can I help you today?", + // Add more responses as needed + }; + + const handleChatIconClick = () => { + setChatboxOpen(!chatboxOpen); + + if (!welcomeMessageDisplayed && !chatboxOpen) { + setChatOutput([...chatOutput, "Hi I am Saarthi, your Platform Guide. How can I help you today?"]); + setWelcomeMessageDisplayed(true); + } + }; + + const handleSendMessage = () => { + if (chatInput.trim()) { + const userMessages = chatInput.trim().split(/[?.!]+/); // Split input by sentence terminators + let updatedChatOutput = []; + + userMessages.forEach((message) => { + const cleanedMessage = message.trim().toLowerCase().replace(/[?,.!]/g, ''); // Clean input + if (cleanedMessage in responses) { + updatedChatOutput.push(responses[cleanedMessage]); + } else { + updatedChatOutput.push("I'm sorry, I don't have an answer for that."); + } + }); + + setChatOutput([...chatOutput, ...updatedChatOutput]); + setChatInput(''); // Clear input + } + }; -const chatbot = () => { return ( -
chatbot
- ) -} +
+
+ Chatbot Icon +
+ + +
+ + {chatboxOpen && ( +
+ +
+ {chatOutput.map((message, index) => ( +

{message}

+ ))} +
+