Skip to content
Snippets Groups Projects
Unverified Commit a2f6545a authored by Avanish Singh's avatar Avanish Singh Committed by GitHub
Browse files

Add files via upload

parent f6f1236f
No related branches found
No related tags found
No related merge requests found
...@@ -3,25 +3,16 @@ import "../styles/style.css"; ...@@ -3,25 +3,16 @@ import "../styles/style.css";
import Header from "./Header"; import Header from "./Header";
import InputSection from "./InputSection"; import InputSection from "./InputSection";
import MessageSection from "./MessageSection"; import MessageSection from "./MessageSection";
import Sidebar from "./Sidebar";
import io from 'socket.io-client'; import io from 'socket.io-client';
import TextMessage from "./TextMessage";
const socket = io(); const socket = io();
const ChatbotComponent = () => { const ChatbotComponent = () => {
const [messages, setMessages] = useState([ const [messages, setMessages] = useState([
]) ])
const [theme, setTheme] = useState('light');
const [area, setArea] = useState('msg_section');
const[update, setUpdate] = useState("reload.png");
const greetingMessage = { const greetingMessage = {
info: "Hey, Welcome to FoodWhizz, What would you like to have today? Say Hey to start...", info: "Hey, Welcome to FoodWhizz, What would you like to have today? Say Hey to start...",
date: getCurrentTime(),
type: "left", type: "left",
name: "FoodWhizz" name: "FoodWhizz"
}; };
...@@ -32,74 +23,18 @@ const ChatbotComponent = () => { ...@@ -32,74 +23,18 @@ const ChatbotComponent = () => {
}, []); }, []);
// Function to handle theme button click
function handleThemeButtonClick(){
const head = document.getElementById("head");
const input = document.getElementById("input");
const input_section = document.getElementById("input_section");
const container = document.getElementById("container");
const body = document.getElementsByTagName("body")[0];
const bar = document.getElementById("sidebar");
const labels = document.getElementsByTagName("ul")[0];
if (theme === 'light'){
setTheme('dark');
setUpdate("https://upload.wikimedia.org/wikipedia/commons/3/38/Solid_white_bordered.png");
setArea('msg_section black');
head.style.background = '#010507';
head.style.color = '#fd8d00';
head.style.borderBottom = '3px solid black';
input.style.background = '#010507';
input.style.borderTop = '3px solid black';
input_section.style.background = 'black';
input_section.style.color = 'white';
input_section.classList.toggle("placeholder-white");
body.style.background = ("recipe1.jpeg");
container.style.border = '3px solid black';
container.style.backgroundColor = '#010507';
bar.style.color = 'black';
labels.style.color = 'black';
}
else {
setTheme('light');
setUpdate("reload.png");
setArea('msg_section');
head.style.background = '#d0d0d0';
head.style.color = '#5b5b5b';
head.style.borderBottom = '3px solid white';
input.style.background = '#d0d0d0';
input.style.borderTop = '3px solid white';
input_section.style.background = 'white';
input_section.style.color = '#5b5b5b';
input_section.classList.remove("placeholder-white");
body.style.background = ("recipe.jpeg");
container.style.border = '3px solid white';
container.style.backgroundColor = '#d0d0d0';
bar.style.color = 'white';
labels.style.color = 'white';
}
};
// Function to add user and bot messages // Function to add user and bot messages
function addMessage(value_info, value_type){ function addMessage(value_info, value_type){
const newUserMessage = createMessage(value_info, value_type, "User"); const newUserMessage = createMessage(value_info, value_type, "User");
setMessages([...messages, newUserMessage]); setMessages([...messages, newUserMessage]);
socket.emit('human',value_info) socket.emit('human',value_info)
socket.on('botmes',(data) =>{ socket.on('bot-message',(data) =>{
const newBotMessage = createMessage(data, "left", "Bot"); const newBotMessage = createMessage(data, "left", "Bot");
setMessages([...messages,newUserMessage,newBotMessage]); setMessages([...messages,newUserMessage,newBotMessage]);
}) })
} }
// Function to get current time
function getCurrentTime() {
const date = new Date();
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');
return `${hours}:${minutes}`;
}
// Function to create a message object // Function to create a message object
function createMessage(value_info, value_type, name){ function createMessage(value_info, value_type, name){
let date = new Date(); let date = new Date();
...@@ -127,10 +62,9 @@ const ChatbotComponent = () => { ...@@ -127,10 +62,9 @@ const ChatbotComponent = () => {
<div> <div>
<input className="down_button" id="top-box" type="checkbox" hidden></input> <input className="down_button" id="top-box" type="checkbox" hidden></input>
<label className="down_label" htmlFor="top-box"></label> <label className="down_label" htmlFor="top-box"></label>
<Sidebar themeButtonClick={handleThemeButtonClick} />
<div className="main" id="container"> <div className="main" id="container">
<Header update={Update} button={update} /> <Header update={Update}/>
<MessageSection messages={messages} area={area} /> <MessageSection messages={messages} area="msg_section" />
<InputSection send_button={addMessage} /> <InputSection send_button={addMessage} />
</div> </div>
<footer>&copy; Copyright 2024</footer> <footer>&copy; Copyright 2024</footer>
......
...@@ -5,10 +5,6 @@ const Header = (props) => { ...@@ -5,10 +5,6 @@ const Header = (props) => {
return ( return (
<div className="header" id="head"> <div className="header" id="head">
FoodWhizz FoodWhizz
<button className="refresh" type="submit" onClick={props.update}>
<img className="update" src={props.button} alt="Refresh Button" />
<img className="update hover" src="reload1.png" alt="Hover Reload Button" />
</button>
</div> </div>
); );
}; };
......
import React, {useRef, useState} from 'react'; import React, {useRef, useState} from 'react';
import '../styles/style.css'; import '../styles/style.css';
const InputArea = (props) => { const InputSection = (props) => {
const [value, setValue] = useState("") const [value, setValue] = useState("")
const textareaRef = useRef(null); const textareaRef = useRef(null);
...@@ -23,7 +23,7 @@ const InputArea = (props) => { ...@@ -23,7 +23,7 @@ const InputArea = (props) => {
return ( return (
<div className="header_bottom" id="input"> <div className="header_bottom" id="input">
<textarea id="input_area" ref={textareaRef} onKeyDown={handleKeyDown} placeholder="say HEY to start" value={value} onChange={event => setValue(event.target.value)}></textarea> <textarea id="input_section" ref={textareaRef} onKeyDown={handleKeyDown} placeholder="say HEY to start" value={value} onChange={event => setValue(event.target.value)}></textarea>
<button className="send_button" type="submit" id="send" onClick={HandleSend}>Send</button> <button className="send_button" type="submit" id="send" onClick={HandleSend}>Send</button>
</div> </div>
); );
...@@ -35,4 +35,4 @@ document.addEventListener('keydown', function(event) { ...@@ -35,4 +35,4 @@ document.addEventListener('keydown', function(event) {
} }
}); });
export default InputArea; export default InputSection;
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