diff --git a/client/src/components/layout/Navbar.tsx b/client/src/components/layout/Navbar.tsx index 7edc820..5020e73 100644 --- a/client/src/components/layout/Navbar.tsx +++ b/client/src/components/layout/Navbar.tsx @@ -10,6 +10,31 @@ import { cn } from '@/lib/utils'; const LANGS = ['EN', 'PT', 'ES'] as const; type Lang = (typeof LANGS)[number]; +interface NavLinkProps { + to: string; + label: string; + active: boolean; +} + +function NavLink({ to, label, active }: NavLinkProps) { + return ( + + {label} + {active && ( + + )} + + ); +} + export function Navbar() { const { isAuthenticated, user, clearAuth } = useAuthStore(); const { theme, toggle } = useThemeStore(); @@ -20,7 +45,12 @@ export function Navbar() { const activeLang = inst.language.toUpperCase().slice(0, 2) as Lang; const handleLogout = async () => { - try { await api.post('/auth/logout'); } finally { clearAuth(); navigate('/'); } + try { + await api.post('/auth/logout'); + } finally { + clearAuth(); + navigate('/'); + } }; const switchLang = (lang: Lang) => { @@ -28,65 +58,45 @@ export function Navbar() { localStorage.setItem('chesskernel-lang', lang.toLowerCase()); }; - const isActive = (to: string) => location.pathname === to || location.pathname.startsWith(to + '/'); + const cycleLang = () => { + const next = LANGS[(LANGS.indexOf(activeLang) + 1) % LANGS.length]; + switchLang(next); + }; + + const isActive = (to: string) => + location.pathname === to || location.pathname.startsWith(to + '/'); return (