'use client'; import { useEffect, useState } from 'react'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { Star, Folder, Inbox, LayoutDashboard, Sparkles, Link2, } from 'lucide-react'; import ThemeToggle from './ThemeToggle'; type Category = { id: number; name: string; color: string; emoji: string | null; member_count?: number; }; type SidebarData = { ok: boolean; total: number; categories: Category[]; }; type DaemonStatus = { ok: boolean; running: boolean; pid?: number; }; export default function Sidebar() { const pathname = usePathname(); const [data, setData] = useState(null); const [daemon, setDaemon] = useState(null); const [unsorted, setUnsorted] = useState(0); const [favorites, setFavorites] = useState(0); useEffect(() => { const load = async () => { try { const r = await fetch('/api/sessions'); const j = await r.json(); setData(j); } catch {} try { const r = await fetch('/api/stats?range=week'); const j = await r.json(); if (j.ok && j.sidebar_counts) { setUnsorted(j.sidebar_counts.unsorted); setFavorites(j.sidebar_counts.favorites); } } catch {} try { const r = await fetch('/api/daemon'); const j = await r.json(); setDaemon(j); } catch {} }; load(); const id = setInterval(load, 30_000); return () => clearInterval(id); }, []); return ( ); } function NavItem({ href, icon, label, badge, count, active, }: { href: string; icon: React.ReactNode; label: string; badge?: string; count?: number; active?: boolean; }) { return ( {active && } {icon} {label} {badge && ( {badge} )} {count !== undefined && ( {count} )} ); } function CategoryItem({ category }: { category: Category }) { return ( {category.emoji ? `${category.emoji} ` : ''} {category.name} {category.member_count ?? 0} ); }