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 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
@ -18,6 +15,7 @@ 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);
@ -39,10 +37,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) {
sendable = true setInputDisabled(false)
endGetWorker() endGetWorker()
} else if (status == 500) { } else if (status == 500) {
sendable = true setInputDisabled(false)
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")
@ -97,7 +95,7 @@ const InputOutputBackend: React.FC = () => {
const editLastMessage = (newContent: string) => { const editLastMessage = (newContent: string) => {
if (newContent == "") { if (newContent == "") {
newContent = "Loading..." newContent = "Generating answer..."
} }
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
@ -118,8 +116,8 @@ const InputOutputBackend: React.FC = () => {
} }
const handleSendClick = (inputValue: string) => { const handleSendClick = (inputValue: string) => {
if (inputValue != "") { if (inputValue != "") {
if (sendable) { if (!inputDisabled) {
sendable=false setInputDisabled(true)
if (postWorkerRef.current) { if (postWorkerRef.current) {
addMessage("user", inputValue) addMessage("user", inputValue)
console.log("input:",inputValue); console.log("input:",inputValue);
@ -158,6 +156,7 @@ 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 from 'react'; import React, { useState } from 'react';
import Login from './Login'; import Login from './Login';
interface HeaderProps { interface HeaderProps {
@ -11,29 +11,32 @@ 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>
<ul> <div className={`hamburger ${menuOpen ? "open" : ""}`} onClick={toggleMenu}>
<li> <span></span>
<button onClick={() => onViewChange('AI')} className="header-button header-logo"> <span></span>
<img src="/img/logo.png" alt="logo" className="header-logo" /> <span></span>
</button> </div>
</li> <nav className={`nav-links ${menuOpen ? "active":""}`}>
<li> <button onClick={() => onViewChange('FAQ')} className="nav-btn">FAQ</button>
<button onClick={() => onViewChange('FAQ')} className="header-button">FAQ</button> <button onClick={() => onViewChange('Documentation')} className="nav-btn">Documentation</button>
</li> {showToggle && showHistoryModelsToggle && (
<li> <button onClick={toggleDivs} className="nav-btn">
<button onClick={() => onViewChange('Documentation')} className="header-button">Documentation</button>
</li>
{showToggle && showHistoryModelsToggle && (
<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,21 +4,25 @@ 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 }, ref: ForwardedRef<HTMLDivElement>) => { ({ message, onSendClick, onMicClick, inputDisabled }, 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 (event.key === 'Enter') { if (!inputDisabled) {
onSendClick(inputValue); // Call the function passed via props if (event.key === 'Enter') {
setInputValue(''); // Optionally clear input after submission onSendClick(inputValue); // Call the function passed via props
event.preventDefault(); // Prevent default action (e.g., form submission) setInputValue(''); // Optionally clear input after submission
event.preventDefault(); // Prevent default action (e.g., form submission)
}
} }
}; };
@ -32,7 +36,7 @@ const InputFrontend = React.forwardRef<HTMLDivElement, InputProps>(
onChange={handleInputChange} onChange={handleInputChange}
onKeyDown={handleKeyDown} 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" /> <img src="/img/send.svg" alt="send" />
</button> </button>
<button type="button" onClick={onMicClick}> <button type="button" onClick={onMicClick}>

View file

@ -10,29 +10,84 @@ 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;
} }
header li { .nav-links{
display: inline-block; display: flex;
margin: 0 15px; gap: 15px;
} }
header img { .nav-btn{
height: 2em; background: transparent;
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;
background-color: transparent; cursor: pointer;
font-size: 1em; /* color */
} }
header a:hover, .nav-btn:hover{
header li button:hover { /* color */
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;
}
}