import { useState } from 'react'; import { FolderOpen, Inbox, FolderPlus, Pencil, Trash2 } from 'lucide-react'; import { useDeleteCollection } from '../hooks/useMemes'; import { CollectionModal } from './CollectionModal'; import type { Collection } from '../api/client'; interface Props { collections: Collection[]; activeId: number | null; onSelect: (id: number) => void; isAdmin: boolean; } export function CollectionBar({ collections, activeId, onSelect, isAdmin }: Props) { const [showCreate, setShowCreate] = useState(false); const [renaming, setRenaming] = useState(null); const deleteCollection = useDeleteCollection(); async function handleDelete(col: Collection) { if (!confirm(`Delete folder "${col.name}"? Its memes will be moved to Unsorted.`)) return; // If the deleted folder is active, switch to Unsorted first if (activeId === col.id) { const unsorted = collections.find((c) => c.is_default); if (unsorted) onSelect(unsorted.id); } await deleteCollection.mutateAsync(col.id); } return ( <>
{collections.map((col) => { const isActive = activeId === col.id; const isDefault = col.is_default === 1; return (
{/* Admin controls — appear on hover for non-default collections */} {isAdmin && !isDefault && (
)}
); })} {/* New folder button (admin only) */} {isAdmin && ( )}
{showCreate && ( setShowCreate(false)} /> )} {renaming && ( setRenaming(null)} /> )} ); }