diff --git a/app/backend/InputOutputHandler.tsx b/app/backend/InputOutputHandler.tsx index 86bb594..12f5d10 100644 --- a/app/backend/InputOutputHandler.tsx +++ b/app/backend/InputOutputHandler.tsx @@ -4,6 +4,9 @@ import ConversationFrontend from "../components/ConversationFrontend"; import InputFrontend from "../components/InputFrontend"; import axios from "axios"; + +let sendable = true + const InputOutputBackend: React.FC = () => { type Message = { role: string @@ -15,7 +18,6 @@ const InputOutputBackend: React.FC = () => { const getWorkerRef = useRef(null) const [messages, setMessages] = useState([{role:"assistant", content:"Hello! How can I help you?"}]) const [liveMessage, setLiveMessage] = useState("") - const [inputDisabled, setInputDisabled] = useState(false) console.log(messages); @@ -37,10 +39,10 @@ const InputOutputBackend: React.FC = () => { postWorkerRef.current.onmessage = (event) => { const status = event.data.status if (status == 200) { - setInputDisabled(false) + sendable = true endGetWorker() } else if (status == 500) { - setInputDisabled(false) + sendable = true if (getWorkerRef.current) { addMessage("assistant", "There was an Error with the AI response") getWorkerRef.current.postMessage("terminate") @@ -95,7 +97,7 @@ const InputOutputBackend: React.FC = () => { const editLastMessage = (newContent: string) => { if (newContent == "") { - newContent = "Generating answer..." + newContent = "Loading..." } setMessages((prevMessages) => { const updatedMessages = prevMessages.slice(); // Create a shallow copy of the current messages @@ -116,8 +118,8 @@ const InputOutputBackend: React.FC = () => { } const handleSendClick = (inputValue: string) => { if (inputValue != "") { - if (!inputDisabled) { - setInputDisabled(true) + if (sendable) { + sendable=false if (postWorkerRef.current) { addMessage("user", inputValue) console.log("input:",inputValue); @@ -156,7 +158,6 @@ const InputOutputBackend: React.FC = () => { message="" onSendClick={handleSendClick} onMicClick={handleMicClick} - inputDisabled={inputDisabled} /> ) diff --git a/app/components/Header.tsx b/app/components/Header.tsx index 26a3f99..96721bd 100644 --- a/app/components/Header.tsx +++ b/app/components/Header.tsx @@ -1,5 +1,5 @@ // Header.tsx -import React, { useState } from 'react'; +import React from 'react'; import Login from './Login'; interface HeaderProps { @@ -11,32 +11,29 @@ interface HeaderProps { } const Header: React.FC = ({ onViewChange, showDivs, toggleDivs, showHistoryModelsToggle, showToggle }) => { - const [menuOpen, setMenuOpen] = useState(false) - - const toggleMenu = () => { - setMenuOpen(!menuOpen) - } - return ( <>
-
- - - -
- - {/* */} + + )} +
diff --git a/app/components/InputFrontend.tsx b/app/components/InputFrontend.tsx index f22ee57..cf9dffc 100644 --- a/app/components/InputFrontend.tsx +++ b/app/components/InputFrontend.tsx @@ -4,25 +4,21 @@ interface InputProps { message: string; onSendClick: (message: string) => void; onMicClick: () => void; - inputDisabled:boolean } const InputFrontend = React.forwardRef( - ({ message, onSendClick, onMicClick, inputDisabled }, ref: ForwardedRef) => { + ({ message, onSendClick, onMicClick }, ref: ForwardedRef) => { const [inputValue, setInputValue] = useState(''); - const handleInputChange = (e: React.ChangeEvent) => { setInputValue(e.target.value); }; const handleKeyDown = (event: React.KeyboardEvent) => { - if (!inputDisabled) { - if (event.key === 'Enter') { - onSendClick(inputValue); // Call the function passed via props - setInputValue(''); // Optionally clear input after submission - event.preventDefault(); // Prevent default action (e.g., form submission) - } + if (event.key === 'Enter') { + onSendClick(inputValue); // Call the function passed via props + setInputValue(''); // Optionally clear input after submission + event.preventDefault(); // Prevent default action (e.g., form submission) } }; @@ -36,7 +32,7 @@ const InputFrontend = React.forwardRef( onChange={handleInputChange} onKeyDown={handleKeyDown} /> -