import { useState } from 'react'; import { Link, useLocation, useNavigate } from 'react-router-dom'; import { Menu, X, LayoutDashboard, Users, MessageSquare, Home, LogIn, LogOut } from 'lucide-react'; import { cn } from '@/lib/utils'; import { useAuth } from '@/contexts/AuthContext'; export default function Navigation() { const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const location = useLocation(); const navigate = useNavigate(); const { isAuthenticated, logout } = useAuth(); const navigationItems = [ { name: 'Home', href: '/', icon: Home, }, { name: 'Synthetic Personas', href: '/synthetic-users', icon: Users, }, { name: 'Focus Groups', href: '/focus-groups', icon: MessageSquare, }, { name: 'Dashboard', href: '/dashboard', icon: LayoutDashboard, }, ]; const toggleMobileMenu = () => { setMobileMenuOpen(!mobileMenuOpen); }; const isActive = (path: string) => { return location.pathname === path; }; // Handle navigation with authentication const handleAuthNavigation = (path: string) => { // Dispatch a custom event when navigating to the synthetic users page // This helps components know when they should refresh data if (path === '/synthetic-users') { // Create and dispatch a custom event that the SyntheticUsers component can listen for const event = new CustomEvent('syntheticUsersNavigation'); window.dispatchEvent(event); } // Always navigate normally - ProtectedRoute will handle auth check navigate(path); }; return (
Semblance
{/* Desktop Navigation */} {/* Mobile Menu Button */}
{/* Mobile Menu */} {mobileMenuOpen && (
{navigationItems.map((item) => (
{item.href === '/' ? ( setMobileMenuOpen(false)} > {item.name} ) : ( )}
))} {/* Mobile Authentication options */} {isAuthenticated ? ( ) : ( setMobileMenuOpen(false)} > Login )}
)}
); }