Complete stabilization pass bringing all 3 stacks to green: Frontend (apps/web/): - Fix TypeScript nullability in useSeason.ts, useTimeOfDay.ts hooks - Disable no-undef in ESLint config (TypeScript handles it; JSX misidentified) - Rename 306 story imports from @storybook/react to @storybook/react-vite - Fix conditional hook call in useMediaQuery.ts useIsTablet - Move useQuery to top of LoginPage.tsx component - Remove useless try/catch in GearFormModal.tsx - Fix stale closure in ResetPasswordPage.tsx handleChange - Make Storybook decorators (withRouter, withQueryClient, withToast, withAudio) no-ops since global StorybookDecorator already provides these — prevents nested Router / duplicate provider crashes in vitest-browser - Fix nested MemoryRouter in 3 page stories (TrackDetail, PlaylistDetail, UserProfile) - Update i18n initialization in test setup (await init before changeLanguage) - Update ~30 test assertions from English to French to match i18n translations - Update test assertions to match SUMI V3 design changes (shadow vs border) - Fix remaining story type errors (PlayerError, PlaylistBatchActions, TrackFilters, VirtualizedChatMessages) Backend (veza-backend-api/): - Fix response_test.go RespondWithAppError signature (2 args, not 3) - Fix TestErrorContractAuthEndpoints expected error codes (ErrCodeUnauthorized vs ErrCodeInvalidCredentials) - Fix TestTrackHandler_GetTrackLikes_Success missing auth middleware setup - Fix TestPlaybackAnalyticsService_GetTrackStats k-anonymity threshold (needs 5 unique users, not 1) - Replace NOW() PostgreSQL function with time.Now() parameter in marketplace service for SQLite test compatibility - Add missing AutoMigrate entries in marketplace_test.go (ProductImage, ProductPreview, ProductLicense, ProductReview) Results: - Frontend TypeCheck: 617 errors -> 0 errors - Frontend ESLint: 349 errors -> 0 errors - Frontend Vitest: 196 failing tests -> 1 skipped (3396/3397 passing) - Backend go vet: 1 error -> 0 errors - Backend tests: 5 failing -> all 13 packages passing - Rust: 150/150 tests passing (unchanged) - Storybook audit: 0 errors across 1244 stories Triage report: docs/TRIAGE_REPORT.md Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
199 lines
No EOL
9.6 KiB
TypeScript
199 lines
No EOL
9.6 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 { usePresenceSync } from '@/features/presence/hooks/usePresenceSync';
|
|
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();
|
|
usePresenceSync(!!user?.id);
|
|
const { theme, setTheme, sidebarOpen, setSidebarOpen } = useUIStore();
|
|
const { t } = useTranslation();
|
|
const navigate = useNavigate();
|
|
|
|
const handleLogout = async () => {
|
|
setIsUserMenuOpen(false);
|
|
await logout();
|
|
// Full page redirect ensures clean state after logout
|
|
window.location.href = '/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 data-testid="app-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-transparent backdrop-blur-[8px] flex items-center justify-between px-4 md:px-6 pointer-events-auto transition-all duration-300',
|
|
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(--sumi-duration-fast)]"
|
|
aria-label="Toggle sidebar"
|
|
>
|
|
<Menu className="w-5 h-5" />
|
|
</button>
|
|
|
|
{/* Mobile Search Button — navigates to search page */}
|
|
<button
|
|
onClick={() => navigate('/search')}
|
|
className="md:hidden flex-1 flex items-center gap-2 h-9 px-3.5 rounded-full bg-[var(--sumi-surface-subtle)] text-muted-foreground/50 text-sm mr-2 transition-colors duration-[var(--sumi-duration-fast)] active:bg-[var(--sumi-bg-hover)]"
|
|
aria-label={t('header.searchAriaLabel')}
|
|
>
|
|
<Search className="w-4 h-4 shrink-0" />
|
|
<span className="truncate">{t('header.searchPlaceholder')}</span>
|
|
</button>
|
|
|
|
{/* Search — Spotify-style: pill shape, smooth focus expansion (desktop) */}
|
|
<div className="flex-1 max-w-lg relative hidden md:block">
|
|
<div
|
|
role="search"
|
|
className="relative flex items-center rounded-full transition-all duration-[var(--sumi-duration-normal)] ease-[var(--sumi-ease-out)] group/search"
|
|
>
|
|
<Search className="absolute left-3.5 w-4 h-4 text-muted-foreground pointer-events-none transition-colors duration-[var(--sumi-duration-fast)] group-focus-within/search:text-primary" />
|
|
<input
|
|
data-testid="search-input"
|
|
type="search"
|
|
placeholder={t('header.searchPlaceholder')}
|
|
aria-label={t('header.searchAriaLabel')}
|
|
className={cn(
|
|
'w-full h-10 pl-10 pr-20 rounded-sm text-sm text-foreground font-heading',
|
|
'bg-transparent border-b border-[var(--sumi-border-faint)] border-t-0 border-l-0 border-r-0',
|
|
'placeholder:text-muted-foreground/30',
|
|
'focus:outline-none focus:border-b-[var(--sumi-accent)] focus:bg-transparent',
|
|
'hover:border-b-[var(--sumi-border-default)]',
|
|
'transition-all duration-300',
|
|
)}
|
|
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-1 px-2 py-1 rounded-md bg-[var(--sumi-bg-overlay)] text-[10px] font-mono font-medium text-muted-foreground/70 border border-[var(--sumi-border-faint)]">
|
|
<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 py-1 text-muted-foreground/40">
|
|
<span className="w-1 h-1 rounded-full bg-[var(--sumi-sage)] shrink-0" />
|
|
<span className="text-[10px] tracking-[0.1em] font-heading" style={{ fontWeight: 300 }}>{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}
|
|
aria-label={t('common.changeTheme')}
|
|
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 (Discord-style) */}
|
|
<div className="relative">
|
|
<button
|
|
data-testid="user-menu"
|
|
onClick={() => setIsUserMenuOpen(!isUserMenuOpen)}
|
|
className="flex items-center gap-2 pl-0.5 pr-2.5 py-0.5 rounded-full hover:bg-[var(--sumi-bg-hover)] transition-all duration-[var(--sumi-duration-normal)] ease-[var(--sumi-ease-out)] focus:outline-none focus:ring-2 focus:ring-ring group"
|
|
>
|
|
<div className="relative w-8 h-8 rounded-full bg-gradient-to-br from-primary/30 to-primary/10 flex items-center justify-center shrink-0 group-hover:ring-2 group-hover:ring-primary/40 group-hover:scale-105 transition-all duration-[var(--sumi-duration-normal)]">
|
|
<span className="text-xs font-bold text-primary">
|
|
{user?.username?.substring(0, 2).toUpperCase() || 'VZ'}
|
|
</span>
|
|
{/* Online indicator */}
|
|
<span className="absolute -bottom-0.5 -right-0.5 w-3 h-3 rounded-full bg-[var(--sumi-sage)] border-2 border-[var(--sumi-bg-base)]" aria-hidden="true" />
|
|
</div>
|
|
<span className="hidden lg:block text-sm font-medium text-foreground truncate max-w-28">
|
|
{user?.username}
|
|
</span>
|
|
</button>
|
|
|
|
{isUserMenuOpen && (
|
|
<FocusTrap active={isUserMenuOpen} onEscape={() => setIsUserMenuOpen(false)}>
|
|
<div className="absolute right-0 top-full mt-2 w-64 bg-[var(--sumi-surface-elevated)] backdrop-blur-2xl rounded-sm shadow-[0_8px_32px_rgba(26,26,30,0.18)] p-1.5 z-50 animate-ink-reveal origin-top-right">
|
|
<div className="px-3 py-3 border-b border-[var(--sumi-border-faint)] mb-1">
|
|
<p className="text-sm font-semibold text-foreground truncate">{user?.username}</p>
|
|
<p className="text-xs text-muted-foreground truncate mt-0.5">{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>
|
|
);
|
|
} |