'use client' import { useCallback } from 'react' import { Note } from '@/types/note' import { NoteCard } from './note-card' import { useNoteListKeyboard } from '@/hooks/use-note-list-keyboard' import { toast } from 'sonner' interface KeyboardNavigableNoteListProps { notes: Note[] onEdit?: (noteId: string) => void } export function KeyboardNavigableNoteList({ notes, onEdit, }: KeyboardNavigableNoteListProps) { const handleFavorite = useCallback(async (noteId: string) => { try { const res = await fetch(`/api/notes/${noteId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ isFavorite: true }), }) if (res.ok) { toast.success('Añadido a favoritos') window.location.reload() } } catch { toast.error('Error al añadir a favoritos') } }, []) const handlePin = useCallback(async (noteId: string) => { try { const res = await fetch(`/api/notes/${noteId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ isPinned: true }), }) if (res.ok) { toast.success('Nota fijada') window.location.reload() } } catch { toast.error('Error al fijar nota') } }, []) const { selectedIndex } = useNoteListKeyboard({ notes, onEdit, onFavorite: handleFavorite, onPin: handlePin, }) if (notes.length === 0) { return (

No hay notas todavía

Crea tu primera nota para comenzar

) } return (
{notes.map((note, index) => (
{index === selectedIndex && (
Enter: abrir | E: editar | F: favoritar | P: fijar
)}
))}
) }