import { prisma } from '@/lib/prisma' import { KeyboardNavigableNoteList } from '@/components/keyboard-navigable-note-list' import { KeyboardHint } from '@/components/keyboard-hint' import { SearchBar } from '@/components/search-bar' import { TagFilter } from '@/components/tag-filter' import { NoteType } from '@/types/note' const NOTE_TYPES: NoteType[] = ['command', 'snippet', 'decision', 'recipe', 'procedure', 'inventory', 'note'] interface SearchParams { q?: string type?: string tag?: string } async function searchNotes(searchParams: SearchParams) { const where: Record = {} if (searchParams.q) { where.OR = [ { title: { contains: searchParams.q } }, { content: { contains: searchParams.q } }, ] } if (searchParams.type && NOTE_TYPES.includes(searchParams.type as NoteType)) { where.type = searchParams.type } if (searchParams.tag) { where.tags = { some: { tag: { name: searchParams.tag }, }, } } const notes = await prisma.note.findMany({ where, include: { tags: { include: { tag: true } } }, orderBy: [{ isPinned: 'desc' }, { updatedAt: 'desc' }], }) return notes } async function getAllTags() { const tags = await prisma.tag.findMany({ orderBy: { name: 'asc' }, }) return tags.map((t) => t.name) } export default async function NotesPage({ searchParams }: { searchParams: Promise }) { const params = await searchParams const [notes, tags] = await Promise.all([searchNotes(params), getAllTags()]) const notesWithTags = notes.map(note => ({ ...note, type: note.type as NoteType, createdAt: note.createdAt.toISOString(), updatedAt: note.updatedAt.toISOString(), tags: note.tags.map(nt => ({ tag: nt.tag })), })) const hasFilters = params.q || params.type || params.tag return (

{hasFilters ? 'Resultados de búsqueda' : 'Todas las notas'}

{hasFilters && (
{params.q && Búsqueda: "{params.q}"} {params.type && Tipo: {params.type}} {params.tag && Tag: {params.tag}}
)}
) }