Compare commits

..

No commits in common. "b539c3592a2aa896e970344dae7101e04eea8258" and "37177a7856c727dd8b5c63b7f6cdcfb358cd1731" have entirely different histories.

4 changed files with 51 additions and 112 deletions

View file

@ -4,6 +4,9 @@ import ConversationFrontend from "../components/ConversationFrontend";
import InputFrontend from "../components/InputFrontend"; import InputFrontend from "../components/InputFrontend";
import axios from "axios"; import axios from "axios";
let sendable = true
const InputOutputBackend: React.FC = () => { const InputOutputBackend: React.FC = () => {
type Message = { type Message = {
role: string role: string
@ -15,7 +18,6 @@ const InputOutputBackend: React.FC = () => {
const getWorkerRef = useRef<Worker | null>(null) const getWorkerRef = useRef<Worker | null>(null)
const [messages, setMessages] = useState<Message[]>([{role:"assistant", content:"Hello! How can I help you?"}]) const [messages, setMessages] = useState<Message[]>([{role:"assistant", content:"Hello! How can I help you?"}])
const [liveMessage, setLiveMessage] = useState("") const [liveMessage, setLiveMessage] = useState("")
const [inputDisabled, setInputDisabled] = useState(false)
console.log(messages); console.log(messages);
@ -37,10 +39,10 @@ const InputOutputBackend: React.FC = () => {
postWorkerRef.current.onmessage = (event) => { postWorkerRef.current.onmessage = (event) => {
const status = event.data.status const status = event.data.status
if (status == 200) { if (status == 200) {
setInputDisabled(false) sendable = true
endGetWorker() endGetWorker()
} else if (status == 500) { } else if (status == 500) {
setInputDisabled(false) sendable = true
if (getWorkerRef.current) { if (getWorkerRef.current) {
addMessage("assistant", "There was an Error with the AI response") addMessage("assistant", "There was an Error with the AI response")
getWorkerRef.current.postMessage("terminate") getWorkerRef.current.postMessage("terminate")
@ -95,7 +97,7 @@ const InputOutputBackend: React.FC = () => {
const editLastMessage = (newContent: string) => { const editLastMessage = (newContent: string) => {
if (newContent == "") { if (newContent == "") {
newContent = "Generating answer..." newContent = "Loading..."
} }
setMessages((prevMessages) => { setMessages((prevMessages) => {
const updatedMessages = prevMessages.slice(); // Create a shallow copy of the current messages const updatedMessages = prevMessages.slice(); // Create a shallow copy of the current messages
@ -116,8 +118,8 @@ const InputOutputBackend: React.FC = () => {
} }
const handleSendClick = (inputValue: string) => { const handleSendClick = (inputValue: string) => {
if (inputValue != "") { if (inputValue != "") {
if (!inputDisabled) { if (sendable) {
setInputDisabled(true) sendable=false
if (postWorkerRef.current) { if (postWorkerRef.current) {
addMessage("user", inputValue) addMessage("user", inputValue)
console.log("input:",inputValue); console.log("input:",inputValue);
@ -156,7 +158,6 @@ const InputOutputBackend: React.FC = () => {
message="" message=""
onSendClick={handleSendClick} onSendClick={handleSendClick}
onMicClick={handleMicClick} onMicClick={handleMicClick}
inputDisabled={inputDisabled}
/> />
</div> </div>
) )

View file

@ -1,5 +1,5 @@
// Header.tsx // Header.tsx
import React, { useState } from 'react'; import React from 'react';
import Login from './Login'; import Login from './Login';
interface HeaderProps { interface HeaderProps {
@ -11,32 +11,29 @@ interface HeaderProps {
} }
const Header: React.FC<HeaderProps> = ({ onViewChange, showDivs, toggleDivs, showHistoryModelsToggle, showToggle }) => { const Header: React.FC<HeaderProps> = ({ onViewChange, showDivs, toggleDivs, showHistoryModelsToggle, showToggle }) => {
const [menuOpen, setMenuOpen] = useState(false)
const toggleMenu = () => {
setMenuOpen(!menuOpen)
}
return ( return (
<> <>
<header> <header>
<div className={`hamburger ${menuOpen ? "open" : ""}`} onClick={toggleMenu}> <ul>
<span></span> <li>
<span></span> <button onClick={() => onViewChange('AI')} className="header-button header-logo">
<span></span> <img src="/img/logo.png" alt="logo" className="header-logo" />
</div> </button>
<nav className={`nav-links ${menuOpen ? "active":""}`}> </li>
<button onClick={() => onViewChange('FAQ')} className="nav-btn">FAQ</button> <li>
<button onClick={() => onViewChange('Documentation')} className="nav-btn">Documentation</button> <button onClick={() => onViewChange('FAQ')} className="header-button">FAQ</button>
</li>
<li>
<button onClick={() => onViewChange('Documentation')} className="header-button">Documentation</button>
</li>
{showToggle && showHistoryModelsToggle && ( {showToggle && showHistoryModelsToggle && (
<button onClick={toggleDivs} className="nav-btn"> <li>
<button onClick={toggleDivs} className="header-button">
{showDivs ? 'Hide History/Models' : 'Show History/Models'} {showDivs ? 'Hide History/Models' : 'Show History/Models'}
</button> </button>
</li>
)} )}
</nav> </ul>
{/* <button onClick={() => onViewChange('AI')} className="header-button header-logo">
<img src="/img/logo.png" alt="logo" className="header-logo" />
</button> */}
<Login /> <Login />
</header> </header>
</> </>

View file

@ -4,26 +4,22 @@ interface InputProps {
message: string; message: string;
onSendClick: (message: string) => void; onSendClick: (message: string) => void;
onMicClick: () => void; onMicClick: () => void;
inputDisabled:boolean
} }
const InputFrontend = React.forwardRef<HTMLDivElement, InputProps>( const InputFrontend = React.forwardRef<HTMLDivElement, InputProps>(
({ message, onSendClick, onMicClick, inputDisabled }, ref: ForwardedRef<HTMLDivElement>) => { ({ message, onSendClick, onMicClick }, ref: ForwardedRef<HTMLDivElement>) => {
const [inputValue, setInputValue] = useState(''); const [inputValue, setInputValue] = useState('');
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setInputValue(e.target.value); setInputValue(e.target.value);
}; };
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => { const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (!inputDisabled) {
if (event.key === 'Enter') { if (event.key === 'Enter') {
onSendClick(inputValue); // Call the function passed via props onSendClick(inputValue); // Call the function passed via props
setInputValue(''); // Optionally clear input after submission setInputValue(''); // Optionally clear input after submission
event.preventDefault(); // Prevent default action (e.g., form submission) event.preventDefault(); // Prevent default action (e.g., form submission)
} }
}
}; };
return ( return (
@ -36,7 +32,7 @@ const InputFrontend = React.forwardRef<HTMLDivElement, InputProps>(
onChange={handleInputChange} onChange={handleInputChange}
onKeyDown={handleKeyDown} onKeyDown={handleKeyDown}
/> />
<button type="button" onClick={() => onSendClick(inputValue)} disabled={inputDisabled?true:false}> <button type="button" onClick={() => onSendClick(inputValue)}>
<img src="/img/send.svg" alt="send" /> <img src="/img/send.svg" alt="send" />
</button> </button>
<button type="button" onClick={onMicClick}> <button type="button" onClick={onMicClick}>

View file

@ -10,84 +10,29 @@ header {
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
z-index: 1000; z-index: 1000;
font-family: var(--font-family); font-family: var(--font-family);
display: flex;
justify-content: space-between;
align-items: center;
} }
.nav-links{ header li {
display: flex; display: inline-block;
gap: 15px; margin: 0 15px;
} }
.nav-btn{ header img {
background: transparent; height: 2em;
vertical-align: middle;
}
header a,
header li button {
color: var(--header-text-color); /* Use the new header text color */
text-decoration: none;
transition: color 0.3s;
border: none; border: none;
cursor: pointer; background-color: transparent;
/* color */ font-size: 1em;
} }
.nav-btn:hover{ header a:hover,
/* color */ header li button:hover {
} color: var(--input-button-color); /* Keep the hover color */
.hamburger{
display: none;
flex-direction: column;
cursor: pointer;
}
.hamburger span{
width: 25px;
height: 3px;
background-color: var(--header-text-color);
margin: 4px;
transition: 0.3s;
}
.hamburger.open span:nth-child(1){
transform: rotate(45deg) translate(5px, 5px);
}
.hamburger.open span:nth-child(2){
opacity: 0;
}
.hamburger.open span:nth-child(3){
transform: rotate(-45deg) translate(5px, -5px);
}
.header-button{
}
.header-button img{
height: 8vh;
}
@media (max-width:768px) {
.nav-links{
display: none;
position: absolute;
top: 60px;
right: 0;
/* background color */
width: 100%;
flex-direction: column;
align-items: flex-start;
padding: 10px;
}
.nav-links.active{
display: flex;
}
.nav-btn{
width: 100%;
text-align: center;
padding: 10px;
}
.hamburger{
display: flex;
}
} }