import { useState, useEffect } from 'react' import ProjectCard from './ProjectCard' import ProjectModal from './ProjectModal' import Button from '../UI/Button' import AgendaPanel from '../Calendar/AgendaPanel' import useProjectStore from '../../store/useProjectStore' import useUIStore from '../../store/useUIStore' import { deleteProject, fetchProjects } from '../../api/projects' const VIEW_OPTIONS = [ { key: 'active', label: 'Active' }, { key: 'archived', label: 'Archived' }, { key: 'all', label: 'All' }, ] export default function ProjectList({ onRegisterNewProject }) { const { projects, removeProject, setProjects } = useProjectStore() const { sidebarTab, setSidebarTab } = useUIStore() const [showModal, setShowModal] = useState(false) const [editing, setEditing] = useState(null) const [projectView, setProjectView] = useState('active') const [search, setSearch] = useState('') useEffect(() => { onRegisterNewProject?.(() => setShowModal(true)) }, [onRegisterNewProject]) const refreshProjects = async () => { const data = await fetchProjects() setProjects(data) } const handleEdit = (p) => { setEditing(p); setShowModal(true) } const handleDelete = async (p) => { if (window.confirm(`Delete "${p.name}" and all its deliverables?`)) { await deleteProject(p.id) removeProject(p.id) } } const handleClose = () => { setShowModal(false); setEditing(null) } const q = search.trim().toLowerCase() const visibleProjects = (projects || []) .filter(p => { const isArchived = !!p.archived_at if (projectView === 'active') return !isArchived if (projectView === 'archived') return isArchived return true }) .filter(p => { if (!q) return true const hay = `${p.name || ''} ${p.description || ''}`.toLowerCase() return hay.includes(q) }) return (
{ e.target.style.display = 'none' }}
/>
{q ? 'No matching projects' : projectView === 'archived' ? 'No archived projects' : 'No projects yet'}
Press N or click + Project