'use client' import { useState } from 'react' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import { Button } from '@/components/ui/button' import { CheckboxList } from '@/components/ui/checkbox-list' import { useNotebooks } from '@/lib/hooks/use-notebooks' import { useCreateNote } from '@/lib/hooks/use-notes' import { LoadingSpinner } from '@/components/common/LoadingSpinner' import { toast } from 'sonner' interface SaveToNotebooksDialogProps { open: boolean onOpenChange: (open: boolean) => void question: string answer: string } export function SaveToNotebooksDialog({ open, onOpenChange, question, answer }: SaveToNotebooksDialogProps) { const [selectedNotebooks, setSelectedNotebooks] = useState([]) const { data: notebooks, isLoading } = useNotebooks(false) // false = not archived const createNote = useCreateNote() const handleToggle = (notebookId: string) => { setSelectedNotebooks(prev => prev.includes(notebookId) ? prev.filter(id => id !== notebookId) : [...prev, notebookId] ) } const handleSave = async () => { if (selectedNotebooks.length === 0) { toast.error('Please select at least one notebook') return } try { // Create note in each selected notebook for (const notebookId of selectedNotebooks) { await createNote.mutateAsync({ title: question, content: answer, note_type: 'ai', notebook_id: notebookId }) } toast.success(`Answer saved to ${selectedNotebooks.length} notebook${selectedNotebooks.length > 1 ? 's' : ''}`) setSelectedNotebooks([]) onOpenChange(false) } catch { toast.error('Failed to save answer') } } const notebookItems = notebooks?.map(nb => ({ id: nb.id, title: nb.name, description: nb.description || undefined })) || [] return ( Save to Notebooks Select one or more notebooks to save this answer
{isLoading ? (
) : ( )}
) }