'use client'; import { useEffect, useState } from 'react'; import { BookOpen, FileText } from 'lucide-react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { useRouter } from 'next/navigation'; interface Note { id: string; title: string; updated_at: string; is_pinned: boolean; } export function RecentNotesWidget() { const [notes, setNotes] = useState([]); const [loading, setLoading] = useState(true); const router = useRouter(); useEffect(() => { fetchNotes(); }, []); async function fetchNotes() { try { const res = await fetch('/api/notes?perPage=5&sort=-updated'); if (res.ok) { const data = await res.json(); setNotes(data.items || []); } } catch {} finally { setLoading(false); } } return (
{loading ? (

Loading...

) : notes.length === 0 ? (

No notes yet

) : (
{notes.map((note) => (
router.push('/notes')} > {note.is_pinned && '📌 '} {note.title} {new Date(note.updated_at).toLocaleDateString()}
))}
)}
); }