start of chatHistory

This commit is contained in:
YasinOnm08 2024-10-08 12:56:28 +02:00
parent dc44bd22d7
commit dbf30fa8a7
3 changed files with 38 additions and 27 deletions

View file

@ -1,30 +1,28 @@
type Message = { // type Message = {
role: string; // role: string;
content:string // content:string
} // }
type Chat = { // type Chat = {
name: string; // name: string;
messages: Message[]; // messages: Message[];
timestamp: number; // timestamp: number;
}; // };
export let chatHistory: Chat[] = []; // export function addMessageToHistory(index: number, chat: Chat): void {
// if (index >= 0 && index < chatHistory.length) {
// chatHistory[index] = chat;
// chatHistory.sort((a, b) => b.timestamp - a.timestamp)
// }
// }
export function addMessageToHistory(index: number, chat: Chat): void { // export function removeMessageFromHistory(timestamp: number): void {
if (index >= 0 && index < chatHistory.length) { // const index = chatHistory.findIndex((msg) => msg.timestamp === timestamp);
chatHistory[index] = chat; // if (index > -1) {
chatHistory.sort((a, b) => b.timestamp - a.timestamp) // chatHistory.splice(index, 1);
} // console.log(`Removed message with timestamp: ${timestamp}`);
} // } else {
// console.log(`Message not found with timestamp: ${timestamp}`);
export function removeMessageFromHistory(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

@ -5,7 +5,6 @@ import InputFrontend from "../components/InputFrontend";
import { sendToVoiceRecognition } from "./voice_backend" import { sendToVoiceRecognition } from "./voice_backend"
import axios from "axios"; import axios from "axios";
import { changeHistory, checkCredentials, getHistory } from './database'; import { changeHistory, checkCredentials, getHistory } from './database';
import { addMessageToHistory, removeMessageFromHistory } from "./ChatHistory";
interface InputOutputHandlerProps { interface InputOutputHandlerProps {
selectedIndex: number; selectedIndex: number;

View file

@ -0,0 +1,14 @@
import { useState } from "react"
const useChatHistory = () => {
type ChatMessages = {
name: string
messages: {}
timestamp: number
}
const [chathistory, setChatHistory] = useState<ChatMessages[]>()
}
export default useChatHistory