2024-10-07 16:41:31 +02:00
|
|
|
import React, { useState } from 'react';
|
2024-10-08 15:33:21 +02:00
|
|
|
import { useChatHistory } from '../hooks/useChatHistory';
|
2024-10-07 16:41:31 +02:00
|
|
|
|
2024-10-08 15:33:21 +02:00
|
|
|
const History: React.FC = () => {
|
2024-10-09 14:22:31 +02:00
|
|
|
const [chatHistory, setSelectedIndex] = useChatHistory()
|
2024-10-08 16:47:40 +02:00
|
|
|
const [isEditing, setIsEditing] = useState(false);
|
|
|
|
const [inputValue, setInputValue] = useState<string>('');
|
|
|
|
|
2024-10-09 14:01:48 +02:00
|
|
|
|
2024-10-08 16:47:40 +02:00
|
|
|
const handleEditButtonClick = () => {
|
|
|
|
setIsEditing(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
setInputValue(e.target.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleSaveButtonClick = () => {
|
|
|
|
setIsEditing(false);
|
|
|
|
chatHistory.chats.push({ name: inputValue, messages: [], timestamp: 5 })
|
|
|
|
setInputValue("")
|
|
|
|
};
|
2024-10-07 16:41:31 +02:00
|
|
|
|
|
|
|
const handleHistoryClick = (index: number) => {
|
|
|
|
setSelectedIndex(index)
|
2024-10-08 16:47:40 +02:00
|
|
|
console.log("index",index);
|
|
|
|
|
2024-10-07 16:41:31 +02:00
|
|
|
}
|
2024-09-18 10:03:36 +02:00
|
|
|
|
2024-10-08 16:47:40 +02:00
|
|
|
|
2024-09-18 10:03:36 +02:00
|
|
|
return (
|
|
|
|
<div className="history-background">
|
|
|
|
<div className="history">
|
|
|
|
<ul>
|
2024-09-18 11:17:34 +02:00
|
|
|
{/* Populate with history items */}
|
2024-10-08 15:33:21 +02:00
|
|
|
{chatHistory.chats.map((chats, index) => (
|
2024-09-18 11:17:34 +02:00
|
|
|
<li key={index}>
|
2024-10-09 15:07:05 +02:00
|
|
|
<a href="#" onClick={() => handleHistoryClick(index)} style={{
|
|
|
|
backgroundColor: chatHistory.selectedIndex == index ? "var(--input-button-color)" : "",
|
|
|
|
borderRadius:"5px"
|
|
|
|
}}>
|
2024-10-09 13:27:35 +02:00
|
|
|
{chatHistory.chats[index].name}
|
|
|
|
</a>
|
2024-09-18 11:17:34 +02:00
|
|
|
</li>
|
|
|
|
))}
|
2024-10-08 16:47:40 +02:00
|
|
|
<li>
|
|
|
|
{isEditing ? (
|
2024-10-09 13:27:35 +02:00
|
|
|
<div className="input-container">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
value={inputValue}
|
|
|
|
onChange={handleInputChange}
|
|
|
|
placeholder="Enter text"
|
|
|
|
className="chat-input"
|
|
|
|
/>
|
|
|
|
<button onClick={handleSaveButtonClick} className="save-btn">
|
|
|
|
Save
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<button onClick={handleEditButtonClick} className="newChat-btn">
|
|
|
|
New Chat
|
|
|
|
</button>
|
|
|
|
)}
|
2024-10-08 16:47:40 +02:00
|
|
|
</li>
|
2024-09-18 11:17:34 +02:00
|
|
|
</ul>
|
2024-09-18 10:03:36 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-10-09 13:27:35 +02:00
|
|
|
);
|
2024-09-18 10:03:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default History;
|