Phase 1:
- S0: Fix open redirect (safeNavigate), delete AuthContext/legacy auth, encrypt API keys, gitignore .env files
- S1: Split client.ts god object into 5 modules, unify toast system, delete unused Sidebar
- S2: Add glass button variant, migrate 32 z-index to SUMI tokens, fix card dark mode
- S3: Skip nav link, aria-hidden on icons, focus-visible ring fixes, alt attrs, aria-live regions
- S4: React.memo on list items, fix key={index}, loading=lazy on images
- S5: Branded loading screen, page transitions respect reduced-motion, LikeButton micro-interaction, i18n sidebar/header
Phase 2 Sprint 6:
- Wire Tailwind shadow utilities to SUMI tokens in @theme block (fixes 50+ files)
- Define shadow-card/shadow-card-hover tokens
- Remove dark:shadow-none workarounds from card.tsx (SUMI handles per-theme shadows)
Co-authored-by: Cursor <cursoragent@cursor.com>
172 lines
No EOL
7.9 KiB
TypeScript
172 lines
No EOL
7.9 KiB
TypeScript
import { useState } from 'react';
|
|
import { Link, useNavigate } from 'react-router-dom';
|
|
import { useAuthStore } from '@/features/auth/store/authStore';
|
|
import { useUser } from '@/features/auth/hooks/useUser';
|
|
import { useUIStore } from '@/stores/ui';
|
|
import { useTranslation } from '@/hooks/useTranslation';
|
|
import { EmailVerificationBadge } from '@/features/auth/components/EmailVerificationBadge';
|
|
import { NotificationMenu } from '@/components/notifications/NotificationMenu';
|
|
import { RateLimitIndicator } from '@/components/RateLimitIndicator';
|
|
import { Button } from '@/components/ui/button';
|
|
import { FocusTrap } from '@/components/ui/focus-trap';
|
|
import { Tooltip } from '@/components/ui/tooltip';
|
|
import { cn } from '@/lib/utils';
|
|
import {
|
|
User,
|
|
Settings,
|
|
LogOut,
|
|
Moon,
|
|
Sun,
|
|
Monitor,
|
|
Search,
|
|
Command,
|
|
Menu,
|
|
} from 'lucide-react';
|
|
import type { BaseComponentProps } from '../types';
|
|
|
|
export interface HeaderProps extends BaseComponentProps { }
|
|
|
|
export function Header(_props: HeaderProps) {
|
|
const [isUserMenuOpen, setIsUserMenuOpen] = useState(false);
|
|
const { logout } = useAuthStore();
|
|
const { data: user } = useUser();
|
|
const { theme, setTheme, sidebarOpen, setSidebarOpen } = useUIStore();
|
|
const { t } = useTranslation();
|
|
const navigate = useNavigate();
|
|
|
|
const handleLogout = async () => {
|
|
await logout();
|
|
navigate('/login');
|
|
};
|
|
|
|
const toggleTheme = () => {
|
|
const newTheme = theme === 'light' ? 'dark' : theme === 'dark' ? 'system' : 'light';
|
|
setTheme(newTheme);
|
|
};
|
|
|
|
const getThemeIcon = () => {
|
|
switch (theme) {
|
|
case 'light': return <Sun className="h-4 w-4" />;
|
|
case 'dark': return <Moon className="h-4 w-4" />;
|
|
default: return <Monitor className="h-4 w-4" />;
|
|
}
|
|
};
|
|
|
|
return (
|
|
<header className="fixed top-0 left-0 right-0 h-header z-[var(--sumi-z-sticky)] pointer-events-none">
|
|
<div className={cn(
|
|
'absolute top-0 right-0 h-header bg-[var(--sumi-glass-bg)] backdrop-blur-[12px] border-b border-[var(--sumi-border-faint)] flex items-center justify-between px-4 md:px-6 pointer-events-auto transition-all duration-[var(--sumi-duration-fast)]',
|
|
sidebarOpen ? 'left-header-expanded' : 'left-header-collapsed',
|
|
'max-lg:left-0'
|
|
)}>
|
|
|
|
{/* Mobile Sidebar Toggle */}
|
|
<button
|
|
onClick={() => setSidebarOpen(!sidebarOpen)}
|
|
className="lg:hidden p-2 rounded-lg hover:bg-muted/50 text-muted-foreground hover:text-foreground mr-2 transition-colors duration-[var(--duration-fast)]"
|
|
>
|
|
<Menu className="w-5 h-5" />
|
|
</button>
|
|
|
|
{/* Search — Spotify-style: navigate to /search on focus or Enter */}
|
|
<div className="flex-1 max-w-md relative hidden md:block group">
|
|
<div
|
|
role="search"
|
|
className="relative flex items-center group/search rounded-full focus-within:ring-2 focus-within:ring-primary/50 transition-all duration-[var(--duration-fast)]"
|
|
>
|
|
<Search className="absolute left-3 w-4 h-4 text-muted-foreground pointer-events-none" />
|
|
<input
|
|
type="search"
|
|
placeholder={t('header.searchPlaceholder')}
|
|
aria-label={t('header.searchAriaLabel')}
|
|
className="w-full h-10 pl-10 pr-4 bg-muted/30 border-0 rounded-full text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-0 focus-visible:ring-2 focus-visible:ring-primary/50 focus-visible:ring-inset transition-all duration-[var(--duration-fast)]"
|
|
onKeyDown={(e) => {
|
|
if (e.key === 'Enter') {
|
|
e.preventDefault();
|
|
const q = (e.currentTarget.value || '').trim();
|
|
navigate(q ? `/search?q=${encodeURIComponent(q)}` : '/search');
|
|
}
|
|
}}
|
|
/>
|
|
<kbd className="absolute right-3 hidden sm:inline-flex items-center gap-0.5 px-2 py-0.5 rounded bg-muted/50 text-xs font-medium text-muted-foreground">
|
|
<Command className="w-3 h-3" />K
|
|
</kbd>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Right Actions */}
|
|
<div className="flex items-center gap-1 ml-2">
|
|
|
|
<div className="hidden xl:flex items-center gap-2 mr-2 px-2.5 py-1 rounded-full bg-muted/30 text-muted-foreground">
|
|
<span className="w-1.5 h-1.5 rounded-full bg-primary shrink-0" />
|
|
<span className="text-xs">{t('header.online')}</span>
|
|
</div>
|
|
|
|
<NotificationMenu />
|
|
<RateLimitIndicator />
|
|
|
|
<div className="h-6 w-px bg-border mx-1" aria-hidden />
|
|
|
|
<Tooltip content={t('common.changeTheme')}>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
onClick={toggleTheme}
|
|
className="min-h-10 min-w-10 rounded-full hover:bg-muted/50 text-muted-foreground hover:text-foreground transition-colors duration-[var(--duration-fast)]"
|
|
>
|
|
{getThemeIcon()}
|
|
</Button>
|
|
</Tooltip>
|
|
|
|
{/* User — compact pill */}
|
|
<div className="relative">
|
|
<button
|
|
onClick={() => setIsUserMenuOpen(!isUserMenuOpen)}
|
|
className="flex items-center gap-2 pl-0.5 pr-2 py-0.5 rounded-full hover:bg-muted/50 transition-colors duration-[var(--duration-fast)] focus:outline-none focus:ring-2 focus:ring-ring group"
|
|
>
|
|
<div className="w-8 h-8 rounded-full bg-primary/20 flex items-center justify-center shrink-0 group-hover:ring-2 group-hover:ring-primary/50 group-hover:scale-105 transition-all">
|
|
<span className="text-xs font-semibold text-primary">
|
|
{user?.username?.substring(0, 2).toUpperCase() || 'VZ'}
|
|
</span>
|
|
</div>
|
|
<span className="hidden lg:block text-sm font-medium text-foreground truncate max-w-24">
|
|
{user?.username}
|
|
</span>
|
|
</button>
|
|
|
|
{isUserMenuOpen && (
|
|
<FocusTrap active={isUserMenuOpen} onEscape={() => setIsUserMenuOpen(false)}>
|
|
<div className="absolute right-0 top-full mt-2 w-56 bg-card backdrop-blur-xl border border-border rounded-xl shadow-xl p-2 z-50 animate-scaleIn origin-top-right">
|
|
<div className="px-3 py-2.5 border-b border-border mb-1">
|
|
<p className="text-sm font-semibold text-foreground truncate">{user?.username}</p>
|
|
<p className="text-xs text-muted-foreground truncate">{user?.email}</p>
|
|
{!user?.is_verified && (
|
|
<div className="mt-2 flex justify-center"><EmailVerificationBadge verified={false} /></div>
|
|
)}
|
|
</div>
|
|
|
|
<div className="p-1 space-y-0.5">
|
|
<Link to="/profile" className="flex items-center gap-3 px-3 py-2.5 text-sm text-muted-foreground hover:text-foreground hover:bg-muted rounded-xl transition-colors duration-[var(--duration-fast)]">
|
|
<User className="w-4 h-4" /> {t('header.profile')}
|
|
</Link>
|
|
<Link to="/settings" className="flex items-center gap-3 px-3 py-2.5 text-sm text-muted-foreground hover:text-foreground hover:bg-muted rounded-xl transition-colors duration-[var(--duration-fast)]">
|
|
<Settings className="w-4 h-4" /> {t('nav.settings')}
|
|
</Link>
|
|
</div>
|
|
|
|
<div className="h-px bg-border my-1" aria-hidden />
|
|
|
|
<div className="p-1">
|
|
<button onClick={handleLogout} className="w-full flex items-center gap-3 px-3 py-2.5 text-sm text-destructive hover:bg-destructive/10 rounded-xl transition-colors duration-[var(--duration-fast)]">
|
|
<LogOut className="w-4 h-4" /> {t('header.signOut')}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</FocusTrap>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
);
|
|
} |