import { useState } from 'react'; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Input } from '@/components/ui/input'; import { Checkbox } from '@/components/ui/checkbox'; import { ScrollArea } from '@/components/ui/scroll-area'; import { useCollections } from '@/hooks/useCollections'; import { collectionsApi } from '@/api/collections'; import type { Collection } from '@/types'; interface AddEntryToCollectionDialogProps { open: boolean; onOpenChange: (open: boolean) => void; entryId: number; entryCollections?: Collection[]; } export function AddEntryToCollectionDialog({ open, onOpenChange, entryId, entryCollections = [], }: AddEntryToCollectionDialogProps) { const [search, setSearch] = useState(''); const { data: allCollections = [] } = useCollections(); const entryCollectionIds = new Set(entryCollections.map((c) => c.id)); const filtered = allCollections.filter((c) => c.name.toLowerCase().includes(search.toLowerCase()) ); const handleToggle = async (collectionId: number, checked: boolean) => { if (checked) { await collectionsApi.addEntry(collectionId, entryId); } else { await collectionsApi.removeEntry(collectionId, entryId); } }; return ( Add to Collection setSearch(e.target.value)} />
{filtered.map((collection) => ( ))} {filtered.length === 0 && (

No collections found.

)}
); }