diff --git a/app/backend/ChatHistory.ts b/app/backend/ChatHistory.ts new file mode 100644 index 0000000..1f5b845 --- /dev/null +++ b/app/backend/ChatHistory.ts @@ -0,0 +1,28 @@ + +// type Message = { +// role: string; +// content:string +// } + +// type Chat = { +// name: string; +// messages: Message[]; +// timestamp: number; +// }; + +// 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}`); +// } +// } diff --git a/app/backend/InputOutputHandler.tsx b/app/backend/InputOutputHandler.tsx index 0dc131c..b630d9c 100644 --- a/app/backend/InputOutputHandler.tsx +++ b/app/backend/InputOutputHandler.tsx @@ -23,7 +23,7 @@ const InputOutputBackend: React.FC = () => { const [preferredMeasurement, setPreferredMeasurement] = useState("metric"); const [timeZone, setTimeZone] = useState("GMT"); const [dateFormat, setDateFormat] = useState("DD-MM-YYYY"); - const [messages, setMessages] = useState([]); + const [messages, setMessages] = useState(chatHistory.chats[chatHistory.selectedIndex].messages || []); const [myBoolean, setMyBoolean] = useState(false); const [systemMessage, setSystemMessage] = useState("You are a helpful assistant") const [weatherData, setWeatherData] = useState("") @@ -38,16 +38,11 @@ const InputOutputBackend: React.FC = () => { console.log(setSelectedIndex) - useEffect(() => { - setMessages(chatHistory.chats[chatHistory.selectedIndex].messages) - }, [chatHistory.selectedIndex]) - useEffect(() => { console.log("History", chatHistory); console.log("Messages", messages); - // Get the current chat's messages const currentMessages = chatHistory.chats[chatHistory.selectedIndex].messages || []; diff --git a/app/components/History.tsx b/app/components/History.tsx index b0b23aa..7e23d6b 100644 --- a/app/components/History.tsx +++ b/app/components/History.tsx @@ -2,11 +2,10 @@ import React, { useState } from 'react'; import { useChatHistory } from '../hooks/useChatHistory'; const History: React.FC = () => { - const [chatHistory, setSelectedIndex, setChatHistory] = useChatHistory() + const [chatHistory, setSelectedIndex] = useChatHistory() const [isEditing, setIsEditing] = useState(false); const [inputValue, setInputValue] = useState(''); - const [hoveredIndex, setHoveredIndex] = useState(null) - + const handleEditButtonClick = () => { setIsEditing(true); @@ -25,73 +24,23 @@ const History: React.FC = () => { const handleHistoryClick = (index: number) => { setSelectedIndex(index) console.log("index",index); - } - - const handleHistoryHover = (index:number) => { - setHoveredIndex(index) - } - - const handleHistoryNotHover = () => { - setHoveredIndex(null) - } - - console.log("chat length",chatHistory.chats.length) - console.log("index",chatHistory.selectedIndex) - - const handleHistoryDeletion = (index: number) => { - const currentIndex = chatHistory.selectedIndex; - - // Create a new copy of the current chat history - const copyChats = { ...chatHistory }; - copyChats.chats = [...chatHistory.chats] - - // Remove the chat at the specified index - copyChats.chats.splice(index,1) - - // Determine new selectedIndex - let newSelectedIndex = currentIndex; - - // Adjust selectedIndex based on the deletion - if (index === currentIndex) { - // If the deleted index is the currently selected one, reset the selected index - newSelectedIndex = copyChats.chats.length > 0 ? (index > 0 ? index - 1 : 0) : -1; // Set to previous or first chat or -1 if no chats left - } else if (index < currentIndex) { - // If the deleted chat is before the current selected index, decrement the selected index - newSelectedIndex = currentIndex - 1; - } - - copyChats.selectedIndex = newSelectedIndex - console.log(copyChats) + } + - // Set the updated chat history - setChatHistory(copyChats); -}; - return (
); -} +}; - export default History; +export default History; diff --git a/app/styles/history.css b/app/styles/history.css index a7126c8..3580acf 100644 --- a/app/styles/history.css +++ b/app/styles/history.css @@ -21,40 +21,14 @@ padding: 10px 0; border-bottom: 1px solid var(--text-color); width: 100%; - height: fit-content; - display: flex; - justify-content: flex-start; - align-items: center; - overflow: hidden; } .history ul li a{ - word-break: break-word; - overflow-wrap: break-word; - display: inline-block; + display: block; text-decoration: none; color: var(--text-color); /* Use variable for link text color */ width: 100%; padding: 5px; } - -#delete-chat-button{ - width: 0; - height: 80%; - visibility: hidden; - border-radius: 5px; - background-color: var(--close-button-color); - transition: all 0.2s ease-in-out; -} - -#delete-chat-button svg{ - width: 100%; - padding: 3px; -} - -#delete-chat-button:hover{ - background-color: var(--close-button-hover-color); -} - .history ul li a:hover{ background-color: var(--input-button-hover-color); } diff --git a/app/styles/models.css b/app/styles/models.css index 3ec64bc..1ccd862 100644 --- a/app/styles/models.css +++ b/app/styles/models.css @@ -45,7 +45,7 @@ display: flex; align-items: center; justify-content: center; - color: white; /* Use variable for text color */ + color: var(--text-color); /* Use variable for text color */ border-radius: 5%; overflow: hidden; position: relative; @@ -67,7 +67,7 @@ display: flex; justify-content: center; align-items: center; - font-size:medium; + font-size: large; transition: opacity 0.5s ease; pointer-events: none; opacity: 0; @@ -85,11 +85,6 @@ .model-box:hover .overlay { opacity: 1; } - -.overlay h3{ - color: var(--overlay-text-color); - width: 95%; -} /* Model background styles */ .code-model { background-image: url(/img/code.jpg);