import { isDefaultTitle } from "../../state/SessionContext" import { formatTimestamp } from "./utils" import { ideBridge } from "../../lib/ideBridge" interface SessionItemProps { session: { id: string title: string | null share?: { url: string } time: { created: number } } isActive: boolean isEditing: boolean isSelectMode: boolean isSelected: boolean selectedSessionIndex: number currentIndex: number editingTitle: string editInputRef: React.RefObject selectedSessionRef: React.RefObject isSharing: boolean onSelect: () => void onEditStart: (e: React.MouseEvent) => void onEditSave: () => void onEditCancel: () => void onEditChange: (value: string) => void onDeleteStart: (e: React.MouseEvent) => void onCheckboxChange: (checked: boolean) => void onKeyDown: (e: React.KeyboardEvent) => void onToggleShare: (e: React.MouseEvent) => void } export function SessionItem({ session, isActive, isEditing, isSelectMode, isSelected, selectedSessionIndex, currentIndex, editingTitle, editInputRef, selectedSessionRef, isSharing, onSelect, onEditStart, onEditSave, onEditCancel, onEditChange, onDeleteStart, onCheckboxChange, onKeyDown, onToggleShare, }: SessionItemProps) { const displayTitle = session.title || "Untitled" const hasDefaultTitle = isDefaultTitle(displayTitle) const isShared = !!session.share?.url const handleLinkClick = (e: React.MouseEvent) => { e.stopPropagation() if (session.share?.url) { if (ideBridge.isInstalled()) { ideBridge.send({ type: "openUrl", payload: { url: session.share.url } }) } else { window.open(session.share.url, "_blank", "noopener,noreferrer") } } } return (
!isEditing && !isSelectMode && onSelect()} onKeyDown={onKeyDown} > {isEditing ? ( onEditChange(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter") { onEditSave() } else if (e.key === "Escape") { onEditCancel() } }} onBlur={onEditSave} onClick={(e) => e.stopPropagation()} className="flex-1 px-1 py-0.5 text-sm bg-white dark:bg-gray-950 border border-blue-500 rounded outline-none text-gray-900 dark:text-gray-100" /> ) : ( <>
{/* Checkbox for selection mode */} {isSelectMode && ( onCheckboxChange(e.target.checked)} onClick={(e) => e.stopPropagation()} className="w-3 h-3 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600" /> )} {isActive && !isSelectMode && ( )} {displayTitle}
{/* Edit and Delete buttons (hidden in select mode) */} {!isSelectMode && (
{/* Timestamp (hidden on hover or when active) */} {formatTimestamp(session.time.created)} {/* Action buttons (visible on hover or when active) */}
{/* Link button (only shown if shared) */} {isShared && ( )} {/* Share/Unshare button */} {/* Edit button */} {/* Delete button */}
)} )}
) }