Merge branch 'main' into main

This commit is contained in:
Patrick 2024-10-01 13:25:53 +02:00
commit 7b25153361
6 changed files with 59 additions and 27 deletions

View file

@ -0,0 +1,27 @@
type ChatMessage = {
name: string;
message: any;
timestamp: number;
};
let chatHistory: ChatMessage[] = [];
function addMessage(name: string, message: any): void {
const newMessage: ChatMessage = {
name: name,
message: message,
timestamp: Date.now()
};
chatHistory.push(newMessage);
console.log(`Added message from ${name}: ${message}`);
}
function removeMessage(timestamp: number): void {
const index = chatHistory.findIndex((msg) => msg.timestamp === timestamp);
if (index > -1) {
chatHistory.splice(index, 1);
console.log(`Removed message with timestamp: ${timestamp}`);
} else {
console.log(`Message not found with timestamp: ${timestamp}`);
}
}

View file

@ -1,6 +1,6 @@
"use client" "use client"
import React, { use, useEffect, useRef, useState } from "react"; import React, { use, useEffect, useRef, useState } from "react";
import ConversationFrontend from "../components/ConversationFrontend"; import ConversationFrontend from '../components/ConversationFrontend';
import InputFrontend from "../components/InputFrontend"; import InputFrontend from "../components/InputFrontend";
import { sendToVoiceRecognition } from "./voice_backend" import { sendToVoiceRecognition } from "./voice_backend"
import axios from "axios"; import axios from "axios";
@ -55,6 +55,7 @@ const InputOutputBackend: React.FC = () => {
}, [preferredCurrency, preferredLanguage, timeFormat, dateFormat, preferredMeasurement, timeZone]); }, [preferredCurrency, preferredLanguage, timeFormat, dateFormat, preferredMeasurement, timeZone]);
const conversationRef = useRef<HTMLDivElement>(null)
const [copyClicked, setCopyClicked] = useState(false) const [copyClicked, setCopyClicked] = useState(false)
const [accessToken, setAccessToken] = useState("") const [accessToken, setAccessToken] = useState("")
const postWorkerRef = useRef<Worker | null>(null) const postWorkerRef = useRef<Worker | null>(null)
@ -269,6 +270,7 @@ const InputOutputBackend: React.FC = () => {
return ( return (
<> <>
<ConversationFrontend <ConversationFrontend
ref={conversationRef}
messages={messages} messages={messages}
onResendClick={handleResendClick} onResendClick={handleResendClick}
onEditClick={handleEditClick} onEditClick={handleEditClick}

View file

@ -14,32 +14,31 @@ interface ConversationProps {
} }
const ConversationFrontend = React.forwardRef<HTMLDivElement, ConversationProps>( const ConversationFrontend = React.forwardRef<HTMLDivElement, ConversationProps>(
({ messages, onResendClick, onEditClick, onCopyClick, isClicked}, ref: ForwardedRef<HTMLDivElement>) => { ({ messages, onResendClick, onEditClick, onCopyClick, isClicked }, ref: ForwardedRef<HTMLDivElement>) => {
const endOfMessagesRef = useRef<HTMLDivElement>(null);
const messagesEndRef = useRef<HTMLDivElement | null>(null)
useEffect(() => {
messagesEndRef.current?.scrollIntoView()
}, [messages])
return ( return (
<div className="output"> <div className="output" ref={ref}>
<div className="conversation resize" id="conversation" ref={ref}> <div className="conversation resize" id="conversation">
{messages.map((message, index) => { {messages.map((message, index) => {
let isUserMessage if (index >= 1) {
if (message.role == "user") {
isUserMessage = message
}
if (index >= 1){
return ( return (
<div <div
key={index} key={index}
className={isUserMessage ? 'user-message' : 'ai-message'} className={message.role === "user" ? 'user-message' : 'ai-message'}
> >
<p> {message.content}</p> <p> {message.content}</p>
</div> </div>
); );
} }
})} })}
{/* Dummy div to mark the end of the conversation for auto-scrolling */}
<div ref={endOfMessagesRef} />
<div className="button-container"> <div className="button-container">
<button type="button" onClick={onResendClick}> <button type="button" onClick={onResendClick}>
<img src="/img/resend.svg" alt="resend" /> <img src="/img/resend.svg" alt="resend" />
@ -50,8 +49,9 @@ const ConversationFrontend = React.forwardRef<HTMLDivElement, ConversationProps>
<button type="button" onClick={onCopyClick}> <button type="button" onClick={onCopyClick}>
<img src="/img/copy.svg" alt="copy" /> <img src="/img/copy.svg" alt="copy" />
</button> </button>
<p id="copiedText" style={{opacity:isClicked?"1":"0", transition:"all 0.3s ease-in-out"}}>Copied!</p> <p id="copiedText" style={{ opacity: isClicked ? "1" : "0", transition: "all 0.3s ease-in-out" }}>Copied!</p>
</div> </div>
<div ref={messagesEndRef} />
</div> </div>
</div> </div>
); );

View file

@ -1,7 +1,7 @@
.history-background { .history-background {
grid-column: 1/2; grid-column: 1/2;
grid-row: 1/2; grid-row: 1/2;
height: 40dvh; height: 35dvh;
overflow: hidden; overflow: hidden;
background-color: var(--history-background-color); background-color: var(--history-background-color);
padding: 1em; padding: 1em;
@ -40,6 +40,6 @@
.history-models{ .history-models{
position: relative; position: relative;
height: 90dvh; height: 86dvh;
/* padding-bottom: 3dvh; */ /* padding-bottom: 3dvh; */
} }

View file

@ -4,6 +4,7 @@
grid-row: 1 / 4; grid-row: 1 / 4;
background-color: var(--output-background-color); background-color: var(--output-background-color);
margin: 1em; margin: 1em;
margin-bottom: 0;
padding-bottom: 14dvh; padding-bottom: 14dvh;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -11,7 +12,7 @@
font-size: 1em; font-size: 1em;
overflow-y: auto; overflow-y: auto;
width: calc(100% - 2em); /* Corrected calculation for width */ width: calc(100% - 2em); /* Corrected calculation for width */
height: 90dvh; height: 86dvh;
} }
#conversation { #conversation {

View file

@ -73,29 +73,31 @@
/* Input styles */ /* Input styles */
.input { .input {
grid-column: 1 / -1; grid-column: 1 / -1;
gap: 10px; gap: 5px;
padding: 0.5em; padding: 0.5em;
margin: 0 auto; margin: 0 auto;
align-items: center; align-items: center;
width: 90%; bottom: 3dvh;
bottom: 10dvh right: 2vw;
left: 2vw;
justify-content: flex-start;
} }
.input input { .input input {
font-size: 1em; /* Adjust font size */ font-size: 1em; /* Adjust font size */
max-width: 65%; max-width: 70%;
margin-right: 0; margin-right: 0;
border-color: var(--input-border-color); /* Use variable for input border */ border-color: var(--input-border-color); /* Use variable for input border */
color: var(--text-color); /* Use variable for text color */ color: var(--text-color); /* Use variable for text color */
} }
.input button { .input button {
height: 40px; /* Adjust button height */ height: 100%; /* Adjust button height */
width: 40px; /* Adjust button width */ width: 15%; /* Adjust button width */
font-size: 1.2em; /* Adjust button font size */ font-size: 1.2em; /* Adjust button font size */
margin: auto;
background-color: var(--input-button-color); /* Use variable for button color */ background-color: var(--input-button-color); /* Use variable for button color */
color: var(--user-message-text-color); /* Use variable for button text color */ color: var(--user-message-text-color); /* Use variable for button text color */
margin: 0;
} }
.header-logo{ .header-logo{