// NoteSelectionModal.jsx - Modal for selecting notes to add to chat context function NoteSelectionModal({ token, onSelect, onClose, t }) { const [notes, setNotes] = useState([]); const [selectedNoteIds, setSelectedNoteIds] = useState([]); const [searchQuery, setSearchQuery] = useState(''); const [loading, setLoading] = useState(true); useEffect(() => { fetchNotes(); }, []); const fetchNotes = async () => { try { setLoading(true); const response = await fetch(`${API_URL}/notes`, { headers: { 'Authorization': `Bearer ${token}` } }); const data = await response.json(); setNotes(data.notes || []); } catch (error) { console.error('Failed to fetch notes:', error); } finally { setLoading(false); } }; const filteredNotes = searchQuery ? notes.filter(note => note.title.toLowerCase().includes(searchQuery.toLowerCase()) || (note.subject && note.subject.toLowerCase().includes(searchQuery.toLowerCase())) ) : notes; const toggleNote = (noteId) => { setSelectedNoteIds(prev => prev.includes(noteId) ? prev.filter(id => id !== noteId) : [...prev, noteId] ); }; const handleCreate = () => { onSelect(selectedNoteIds); }; return (
{t('common.loading') || 'Loading...'}
{searchQuery ? (t('ask.noNotesFound') || 'No notes found') : (t('ask.noNotesAvailable') || 'No notes available')}