import { useEffect } from 'react'; import { Plus } from 'lucide-react'; import { useNotesStore } from '../stores/notes'; import { NoteList } from './NoteList'; import { NoteEditor } from './NoteEditor'; import { Button } from '@yetanother/ui'; import { loadNotes, createNote } from '../lib/node-service'; export function NotesPage() { const notes = useNotesStore((s) => s.notes); const setSelectedNoteId = useNotesStore((s) => s.setSelectedNoteId); const loading = useNotesStore((s) => s.loading); useEffect(() => { loadNotes(); }, []); const handleCreate = async () => { try { const note = await createNote({ title: '', workspaceId: notes[0]?.workspaceId ?? crypto.randomUUID(), }); setSelectedNoteId(note.id as string); } catch (err) { const now = new Date().toISOString(); const fallback = { id: crypto.randomUUID(), title: '', type: 'note' as const, content: { type: 'doc', content: [{ type: 'paragraph' }] }, plainText: '', status: 'active' as const, workspaceId: crypto.randomUUID(), tags: [], folderId: null, createdAt: now, updatedAt: now, }; useNotesStore.getState().addNote(fallback); setSelectedNoteId(fallback.id); } }; return (
); }