kanban-app/frontend/src/components/Navbar.tsx

147 lines
5 KiB
TypeScript
Raw Normal View History

2026-02-25 09:29:45 +00:00
import { Link } from 'react-router-dom';
2026-03-15 15:45:27 +00:00
import { useState } from 'react';
2026-02-25 09:29:45 +00:00
import { useApp } from '../context/AppContext';
import { useAuth } from '../hooks/useAuth';
import { TaskboardLogo } from './TaskboardLogo';
2026-03-15 15:45:27 +00:00
import MenuIcon from './icons/MenuIcon';
import CloseIcon from './icons/CloseIcon';
2026-02-24 08:52:57 +00:00
export function Navbar() {
2026-02-25 09:29:45 +00:00
const { user } = useApp();
const { logout } = useAuth();
2026-03-15 15:45:27 +00:00
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
2026-02-24 08:52:57 +00:00
return (
<nav className="bg-gray-800 border-b border-gray-700 shadow-md">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex items-center justify-between h-16">
2026-03-15 15:45:27 +00:00
<div className="flex items-center">
<Link to="/boards" className="hover:opacity-80 transition-opacity flex-shrink-0">
<TaskboardLogo className="h-8 w-auto" />
</Link>
2026-02-25 09:29:45 +00:00
<Link
to="/boards"
2026-03-15 15:45:27 +00:00
className="text-xl font-bold text-white hover:text-blue-400 transition-colors ml-2"
2026-02-25 09:29:45 +00:00
>
Taskboard
2026-02-24 08:52:57 +00:00
</Link>
2026-03-15 15:45:27 +00:00
<div className="hidden md:flex items-baseline ml-10 space-x-4">
2026-02-24 08:52:57 +00:00
<Link
to="/home"
2026-02-24 08:52:57 +00:00
className="text-gray-300 hover:text-white px-3 py-2 rounded-md text-sm font-medium transition-colors"
>
Home
</Link>
2026-02-24 08:52:57 +00:00
{user && (
<Link
to="/boards"
className="text-gray-300 hover:text-white px-3 py-2 rounded-md text-sm font-medium transition-colors"
>
Boards
</Link>
2026-02-24 08:52:57 +00:00
)}
</div>
</div>
2026-03-15 15:45:27 +00:00
<div className="hidden md:flex items-center gap-3">
2026-02-24 08:52:57 +00:00
{user ? (
<>
<span className="text-gray-300 px-3 py-2">{user.username}</span>
<button
onClick={logout}
className="text-gray-300 hover:text-white px-3 py-2 rounded-md text-sm font-medium transition-colors"
>
Logout
</button>
</>
2026-02-24 08:52:57 +00:00
) : (
<>
<Link
to="/login"
className="text-gray-300 hover:text-white px-3 py-2 rounded-md text-sm font-medium transition-colors"
>
Login
</Link>
<Link
to="/register"
className="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md text-sm font-medium transition-colors"
>
Register
</Link>
</>
)}
</div>
2026-03-15 15:45:27 +00:00
<div className="md:hidden flex items-center">
<button
onClick={() => setMobileMenuOpen(!mobileMenuOpen)}
className="text-gray-300 hover:text-white p-2 rounded-md"
aria-label="Toggle menu"
>
{mobileMenuOpen ? <CloseIcon /> : <MenuIcon />}
</button>
</div>
2026-02-24 08:52:57 +00:00
</div>
</div>
2026-03-15 15:45:27 +00:00
{/* Mobile menu */}
{mobileMenuOpen && (
<div className="md:hidden bg-gray-800 border-t border-gray-700">
<div className="px-2 pt-2 pb-3 space-y-1 sm:px-3">
<Link
to="/home"
className="text-gray-300 hover:text-white block px-3 py-2 rounded-md text-base font-medium"
onClick={() => setMobileMenuOpen(false)}
>
Home
</Link>
{user && (
<Link
to="/boards"
className="text-gray-300 hover:text-white block px-3 py-2 rounded-md text-base font-medium"
onClick={() => setMobileMenuOpen(false)}
>
Boards
</Link>
)}
<div className="border-t border-gray-700 my-2"></div>
{user ? (
<>
<div className="px-3 py-2 text-gray-300 text-base font-medium">{user.username}</div>
<button
onClick={() => {
logout();
setMobileMenuOpen(false);
}}
className="text-gray-300 hover:text-white block w-full text-left px-3 py-2 rounded-md text-base font-medium"
>
Logout
</button>
</>
) : (
<>
<Link
to="/login"
className="text-gray-300 hover:text-white block px-3 py-2 rounded-md text-base font-medium"
onClick={() => setMobileMenuOpen(false)}
>
Login
</Link>
<Link
to="/register"
className="bg-blue-600 hover:bg-blue-700 text-white block px-3 py-2 rounded-md text-base font-medium"
onClick={() => setMobileMenuOpen(false)}
>
Register
</Link>
</>
)}
</div>
</div>
)}
2026-02-24 08:52:57 +00:00
</nav>
2026-02-25 09:29:45 +00:00
);
}