import React, { useState } from "react"; import { motion } from "framer-motion"; import { FolderOpen, Calendar, FileText, ChevronRight, Settings, MoreVertical } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { useTranslation } from "@/hooks/useTranslation"; import type { Project } from "@/lib/api"; import { cn } from "@/lib/utils"; import { formatTimeAgo } from "@/lib/date-utils"; import { Pagination } from "@/components/ui/pagination"; interface ProjectListProps { /** * Array of projects to display */ projects: Project[]; /** * Callback when a project is clicked */ onProjectClick: (project: Project) => void; /** * Callback when hooks configuration is clicked */ onProjectSettings?: (project: Project) => void; /** * Whether the list is currently loading */ loading?: boolean; /** * Optional className for styling */ className?: string; } const ITEMS_PER_PAGE = 12; /** * Extracts the project name from the full path */ const getProjectName = (path: string): string => { const parts = path.split('/').filter(Boolean); return parts[parts.length - 1] || path; }; /** * ProjectList component - Displays a paginated list of projects with hover animations * * @example * console.log('Selected:', project)} * /> */ export const ProjectList: React.FC = ({ projects, onProjectClick, onProjectSettings, className, }) => { const { t } = useTranslation(); const [currentPage, setCurrentPage] = useState(1); // Calculate pagination const totalPages = Math.ceil(projects.length / ITEMS_PER_PAGE); const startIndex = (currentPage - 1) * ITEMS_PER_PAGE; const endIndex = startIndex + ITEMS_PER_PAGE; const currentProjects = projects.slice(startIndex, endIndex); // Reset to page 1 if projects change React.useEffect(() => { setCurrentPage(1); }, [projects.length]); return (
{currentProjects.map((project, index) => ( onProjectClick(project)} >

{getProjectName(project.path)}

{project.sessions.length > 0 && ( {project.sessions.length} )}

{project.path}

{formatTimeAgo(project.created_at * 1000)}
{project.sessions.length}
{onProjectSettings && ( e.stopPropagation()}> { e.stopPropagation(); onProjectSettings(project); }} > {t('settings.hooks')} )}
))}
); };