'use client'; import { useState, useEffect } from 'react'; import Link from 'next/link'; import Image from 'next/image'; import { usePathname, useRouter } from 'next/navigation'; import { useAuth } from '@/lib/contexts/AuthContext'; import { HomeIcon, SearchIcon, BellIcon, UserIcon, ShieldIcon, SettingsIcon, BotIcon } from './Icons'; import { formatFullHandle } from '@/lib/utils/handle'; import { LogOut, Settings2 } from 'lucide-react'; // import { IdentityUnlockPrompt } from './IdentityUnlockPrompt'; // Moved to LayoutWrapper export function Sidebar() { const { user, isAdmin, logout } = useAuth(); const pathname = usePathname(); const router = useRouter(); const [customLogoUrl, setCustomLogoUrl] = useState(undefined); const [unreadCount, setUnreadCount] = useState(0); const [unreadChatCount, setUnreadChatCount] = useState(0); const [loggingOut, setLoggingOut] = useState(false); useEffect(() => { fetch('/api/node') .then(res => res.json()) .then(data => { setCustomLogoUrl(data.logoUrl || null); }) .catch(() => { setCustomLogoUrl(null); }); }, []); // Fetch unread notification count useEffect(() => { if (!user) return; const fetchUnread = () => { fetch('/api/notifications?unread=true&limit=50') .then(res => res.json()) .then(data => { setUnreadCount(data.notifications?.length || 0); }) .catch(() => { }); }; fetchUnread(); // Poll every 30 seconds const interval = setInterval(fetchUnread, 30000); return () => clearInterval(interval); }, [user]); // Fetch unread chat count useEffect(() => { if (!user) return; const fetchUnreadChats = () => { fetch('/api/chat/unread') .then(res => res.json()) .then(data => { setUnreadChatCount(data.unreadCount || 0); }) .catch(() => { }); }; fetchUnreadChats(); // Poll every 10 seconds const interval = setInterval(fetchUnreadChats, 10000); return () => clearInterval(interval); }, [user]); // Home is exact match const isHome = pathname === '/'; const handleLogout = async () => { if (loggingOut) return; setLoggingOut(true); try { await logout(); window.location.href = '/explore'; } catch (error) { console.error('Logout failed:', error); setLoggingOut(false); } }; return ( ); }