From dbf30fa8a7d73c172de7834be524b45009091095 Mon Sep 17 00:00:00 2001
From: YasinOnm08 <onmazyasin4@gmail.com>
Date: Tue, 8 Oct 2024 12:56:28 +0200
Subject: [PATCH] start of chatHistory

---
 app/backend/ChatHistory.ts         | 50 ++++++++++++++----------------
 app/backend/InputOutputHandler.tsx |  1 -
 app/hooks/useChatHistory.tsx       | 14 +++++++++
 3 files changed, 38 insertions(+), 27 deletions(-)
 create mode 100644 app/hooks/useChatHistory.tsx

diff --git a/app/backend/ChatHistory.ts b/app/backend/ChatHistory.ts
index b7b28c1..1f5b845 100644
--- a/app/backend/ChatHistory.ts
+++ b/app/backend/ChatHistory.ts
@@ -1,30 +1,28 @@
 
-type Message = {
-    role: string;
-    content:string
-}
+// type Message = {
+//     role: string;
+//     content:string
+// }
 
-type Chat = {
-    name: string;
-    messages: Message[];
-    timestamp: number;
-};
+// type Chat = {
+//     name: string;
+//     messages: Message[];
+//     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 {
-    if (index >= 0 && index < chatHistory.length) {
-        chatHistory[index] = chat;
-        chatHistory.sort((a, b) => b.timestamp - a.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}`);
-    }
-}
+// 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}`);
+//     }
+// }
diff --git a/app/backend/InputOutputHandler.tsx b/app/backend/InputOutputHandler.tsx
index dffc1bf..884cdd4 100644
--- a/app/backend/InputOutputHandler.tsx
+++ b/app/backend/InputOutputHandler.tsx
@@ -5,7 +5,6 @@ import InputFrontend from "../components/InputFrontend";
 import { sendToVoiceRecognition } from "./voice_backend"
 import axios from "axios";
 import { changeHistory, checkCredentials, getHistory } from './database';
-import { addMessageToHistory, removeMessageFromHistory } from "./ChatHistory";
 
 interface InputOutputHandlerProps {
   selectedIndex: number;
diff --git a/app/hooks/useChatHistory.tsx b/app/hooks/useChatHistory.tsx
new file mode 100644
index 0000000..06fa851
--- /dev/null
+++ b/app/hooks/useChatHistory.tsx
@@ -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
\ No newline at end of file