import { Conversation, KeyValuePair } from "@/types"; import { IconCheck, IconMessage, IconPencil, IconTrash, IconX } from "@tabler/icons-react"; import { DragEvent, FC, KeyboardEvent, useEffect, useState } from "react"; interface Props { selectedConversation: Conversation; conversation: Conversation; loading: boolean; onSelectConversation: (conversation: Conversation) => void; onDeleteConversation: (conversation: Conversation) => void; onUpdateConversation: (conversation: Conversation, data: KeyValuePair) => void; } export const ConversationComponent: FC = ({ selectedConversation, conversation, loading, onSelectConversation, onDeleteConversation, onUpdateConversation }) => { const [isDeleting, setIsDeleting] = useState(false); const [isRenaming, setIsRenaming] = useState(false); const [renameValue, setRenameValue] = useState(""); const handleEnterDown = (e: KeyboardEvent) => { if (e.key === "Enter") { e.preventDefault(); handleRename(selectedConversation); } }; const handleDragStart = (e: DragEvent, conversation: Conversation) => { if (e.dataTransfer) { e.dataTransfer.setData("conversation", JSON.stringify(conversation)); } }; const handleRename = (conversation: Conversation) => { onUpdateConversation(conversation, { key: "name", value: renameValue }); setRenameValue(""); setIsRenaming(false); }; useEffect(() => { if (isRenaming) { setIsDeleting(false); } else if (isDeleting) { setIsRenaming(false); } }, [isRenaming, isDeleting]); return ( ); };