import React, { useState, useRef, useEffect } from 'react' import { useNavigate } from 'react-router-dom' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faChevronRight, faRightFromBracket, faUserCircle, faGear, faHome, faPersonHiking, faHighlighter, faBookmark, faPenToSquare, faLink } from '@fortawesome/free-solid-svg-icons' import { Hooks } from 'applesauce-react' import { useEventModel } from 'applesauce-react/hooks' import { Models } from 'applesauce-core' import IconButton from './IconButton' import { faBooks } from '../icons/customIcons' interface SidebarHeaderProps { onToggleCollapse: () => void onLogout: () => void onOpenSettings: () => void isMobile?: boolean } const SidebarHeader: React.FC = ({ onToggleCollapse, onLogout, onOpenSettings, isMobile = false }) => { const navigate = useNavigate() const activeAccount = Hooks.useActiveAccount() const profile = useEventModel(Models.ProfileModel, activeAccount ? [activeAccount.pubkey] : null) const [showProfileMenu, setShowProfileMenu] = useState(false) const menuRef = useRef(null) const getProfileImage = () => { return profile?.picture || null } const getUserDisplayName = () => { if (!activeAccount) return 'Unknown User' if (profile?.name) return profile.name if (profile?.display_name) return profile.display_name if (profile?.nip05) return profile.nip05 return `${activeAccount.pubkey.slice(0, 8)}...${activeAccount.pubkey.slice(-8)}` } const profileImage = getProfileImage() // Close menu when clicking outside useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (menuRef.current && !menuRef.current.contains(event.target as Node)) { setShowProfileMenu(false) } } if (showProfileMenu) { document.addEventListener('mousedown', handleClickOutside) } return () => { document.removeEventListener('mousedown', handleClickOutside) } }, [showProfileMenu]) const handleMenuItemClick = (action: () => void) => { setShowProfileMenu(false) // Close mobile sidebar when navigating on mobile if (isMobile) { onToggleCollapse() } action() } return ( <>
{activeAccount && (
{showProfileMenu && (
)}
)} { if (isMobile) { onToggleCollapse() } navigate('/') }} title="Home" ariaLabel="Home" variant="ghost" />
{ if (isMobile) { onToggleCollapse() } navigate('/explore') }} title="Explore" ariaLabel="Explore" variant="ghost" /> { if (isMobile) { onToggleCollapse() } onOpenSettings() }} title="Settings" ariaLabel="Settings" variant="ghost" /> {!isMobile && ( )}
) } export default SidebarHeader