import { useParams } from '@remix-run/react'; import { classNames } from '~/utils/classNames'; import { type ChatHistoryItem } from '~/lib/persistence'; import WithTooltip from '~/components/ui/Tooltip'; import { useEditChatDescription } from '~/lib/hooks'; import { forwardRef, type ForwardedRef, useCallback } from 'react'; import { Checkbox } from '~/components/ui/Checkbox'; interface HistoryItemProps { item: ChatHistoryItem; onDelete?: (event: React.UIEvent) => void; onDuplicate?: (id: string) => void; exportChat: (id?: string) => void; selectionMode?: boolean; isSelected?: boolean; onToggleSelection?: (id: string) => void; } export function HistoryItem({ item, onDelete, onDuplicate, exportChat, selectionMode = false, isSelected = false, onToggleSelection, }: HistoryItemProps) { const { id: urlId } = useParams(); const isActiveChat = urlId === item.urlId; const { editing, handleChange, handleBlur, handleSubmit, handleKeyDown, currentDescription, toggleEditMode } = useEditChatDescription({ initialDescription: item.description, customChatId: item.id, syncWithGlobalStore: isActiveChat, }); const handleItemClick = useCallback( (e: React.MouseEvent) => { if (selectionMode) { e.preventDefault(); e.stopPropagation(); console.log('Item clicked in selection mode:', item.id); onToggleSelection?.(item.id); } }, [selectionMode, item.id, onToggleSelection], ); const handleCheckboxChange = useCallback(() => { console.log('Checkbox changed for item:', item.id); onToggleSelection?.(item.id); }, [item.id, onToggleSelection]); const handleDeleteClick = useCallback( (event: React.MouseEvent) => { event.preventDefault(); event.stopPropagation(); console.log('Delete button clicked for item:', item.id); if (onDelete) { onDelete(event as unknown as React.UIEvent); } }, [onDelete, item.id], ); return (
{selectionMode && (
e.stopPropagation()}>
)} {editing ? (
); } const ChatActionButton = forwardRef( ( { toolTipContent, icon, className, onClick, }: { toolTipContent: string; icon: string; className?: string; onClick: (event: React.MouseEvent) => void; btnTitle?: string; }, ref: ForwardedRef, ) => { return (