Compare commits

..

2 commits

Author SHA1 Message Date
b539c3592a started hamburger menu 2024-09-24 14:54:39 +02:00
615a58ce28 no input while generating/empty 2024-09-24 13:50:46 +02:00
4 changed files with 112 additions and 51 deletions

View file

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

View file

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

View file

@ -4,22 +4,26 @@ interface InputProps {
message: string;
onSendClick: (message: string) => void;
onMicClick: () => void;
inputDisabled:boolean
}
const InputFrontend = React.forwardRef<HTMLDivElement, InputProps>(
({ message, onSendClick, onMicClick }, ref: ForwardedRef<HTMLDivElement>) => {
({ message, onSendClick, onMicClick, inputDisabled }, ref: ForwardedRef<HTMLDivElement>) => {
const [inputValue, setInputValue] = useState('');
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setInputValue(e.target.value);
};
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
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)
}
}
};
return (
@ -32,7 +36,7 @@ const InputFrontend = React.forwardRef<HTMLDivElement, InputProps>(
onChange={handleInputChange}
onKeyDown={handleKeyDown}
/>
<button type="button" onClick={() => onSendClick(inputValue)}>
<button type="button" onClick={() => onSendClick(inputValue)} disabled={inputDisabled?true:false}>
<img src="/img/send.svg" alt="send" />
</button>
<button type="button" onClick={onMicClick}>

View file

@ -10,29 +10,84 @@ header {
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
z-index: 1000;
font-family: var(--font-family);
display: flex;
justify-content: space-between;
align-items: center;
}
header li {
display: inline-block;
margin: 0 15px;
.nav-links{
display: flex;
gap: 15px;
}
header img {
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;
.nav-btn{
background: transparent;
border: none;
background-color: transparent;
font-size: 1em;
cursor: pointer;
/* color */
}
header a:hover,
header li button:hover {
color: var(--input-button-color); /* Keep the hover color */
.nav-btn: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;
}
}