import React, { useState, useEffect } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { ChevronDown, Edit2, FileText, Loader2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { cn } from "@/lib/utils"; import { api, type ClaudeMdFile } from "@/lib/api"; import { formatUnixTimestamp } from "@/lib/date-utils"; interface ClaudeMemoriesDropdownProps { /** * The project path to search for CLAUDE.md files */ projectPath: string; /** * Callback when an edit button is clicked */ onEditFile: (file: ClaudeMdFile) => void; /** * Optional className for styling */ className?: string; } /** * ClaudeMemoriesDropdown component - Shows all CLAUDE.md files in a project * * @example * console.log('Edit file:', file)} * /> */ export const ClaudeMemoriesDropdown: React.FC = ({ projectPath, onEditFile, className, }) => { const [isOpen, setIsOpen] = useState(false); const [files, setFiles] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); // Load CLAUDE.md files when dropdown opens useEffect(() => { if (isOpen && files.length === 0) { loadClaudeMdFiles(); } }, [isOpen]); const loadClaudeMdFiles = async () => { try { setLoading(true); setError(null); const foundFiles = await api.findClaudeMdFiles(projectPath); setFiles(foundFiles); } catch (err) { console.error("Failed to load CLAUDE.md files:", err); setError("Failed to load CLAUDE.md files"); } finally { setLoading(false); } }; const formatFileSize = (bytes: number): string => { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; }; return (
{/* Dropdown Header */} {/* Dropdown Content */} {isOpen && (
{loading ? (
) : error ? (
{error}
) : files.length === 0 ? (
No CLAUDE.md files found in this project
) : (
{files.map((file, index) => (

{file.relative_path}

{formatFileSize(file.size)} Modified {formatUnixTimestamp(file.modified)}
))}
)}
)}
); };