import { useEffect, useState } from 'react'; import { FolderPlus, FolderTree, Loader2, Trash2 } from 'lucide-react'; import { toast } from 'sonner'; import { DirectoryPicker } from 'officerdev'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { useProjects, useSelectedProject } from './useKanban'; /** * Which board you are looking at, and the folders you can look at. * * ── This panel is the whole point of the extraction ── * * The version of this in the platform had no such panel and could not have had one: it read * `resolve(process.cwd(), 'todo')`, so there was exactly one board and no question to ask. Everything * else in this plugin came across nearly unchanged; this is the part that is new. * * ── Selecting writes the URL ── * * `?project=`. The board is a sibling that reads it — the two never speak. So a board is linkable, * survives a reload, and the detail pane can be opened from a link without this panel having rendered. */ export const ProjectsPanel = () => { const { projects, isLoading, add, remove } = useProjects(); const { selected, select } = useSelectedProject(); const [adding, setAdding] = useState(false); const [name, setName] = useState(''); const [path, setPath] = useState(''); const [confirming, setConfirming] = useState(null); const [picking, setPicking] = useState(false); /* Land on something rather than on nothing. With projects but none selected the board would render its empty state, which reads as "this project has no items" when the truth is "no project is chosen". Only when nothing is selected — never overriding a choice, and never fighting a link somebody followed to a specific board. */ useEffect(() => { if (selected === null && projects.length > 0) select(projects[0]!.id); }, [selected, projects, select]); const submit = (event: React.FormEvent) => { event.preventDefault(); if (!name.trim() || !path.trim()) return; add.mutate( { name: name.trim(), path: path.trim() }, { onSuccess: (project) => { setName(''); setPath(''); setAdding(false); select(project.id); }, onError: (err: unknown) => toast.error(err instanceof Error ? err.message : 'could not add that folder'), }, ); }; return ( ); };