import { Link } from 'react-router-dom' import { useQuery } from '@tanstack/react-query' import Dropdown, { DropdownGroup } from '../ui/Dropdown' import GlobalSearch from './GlobalSearch' import { Avatar, Icon } from '../ui/primitives' import { seedQuery, useSeedMutation } from '../data/seedQueries' import { useToast } from '../ui/Toast' import { useTheme } from '../theme/ThemeProvider' import { useAuth } from '../auth/AuthContext' function initialsFromName(name) { const parts = String(name || '').trim().split(/\s+/).filter(Boolean) if (!parts.length) return '?' if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase() return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase() } export default function Topbar({ onOpenNav, searchRef }) { const { theme, toggleTheme } = useTheme() const { user, signOut } = useAuth() const { toast } = useToast() const { data: notifications = [] } = useQuery(seedQuery('notifications')) const { data: messages = [] } = useQuery(seedQuery('messages')) const updateNotifications = useSeedMutation('notifications') // App.hydrateProfile's DOM sweep is gone — the session is read directly. const name = user?.name || 'Guest' const email = user?.email || '' const role = user?.role_name || user?.role || 'Member' function markAllRead() { updateNotifications((ns) => ns.map((n) => ({ ...n, unread: false }))) toast('All notifications marked as read', 'success') } return (
( )} >
Messages
{messages.map((m) => (
{m.name}
{m.text}
{m.time} ago
))}
Open inbox
( )} >
Notifications
{notifications.slice(0, 6).map((n) => (
{n.title}
{n.text}
{n.time}
))}
View all
( )} >
{initialsFromName(name)}
{name}
{email}
My Profile Settings Help Center
) }