Spaces:
Sleeping
Sleeping
Download src/components/Header.tsx from Musabek/NOVAESPORT: direct link, hf CLI and curl.
- Browser
- Download file 18.6 kB
-
https://huggingface.co/spaces/Musabek/NOVAESPORT/resolve/main/src/components/Header.tsx
- Command line
-
hf download hf://spaces/Musabek/NOVAESPORT/src/components/Header.tsx
-
curl -L -o Header.tsx https://huggingface.co/spaces/Musabek/NOVAESPORT/resolve/main/src/components/Header.tsx
18.6 kB
| import React, { useState } from 'react'; | |
| import { User, AppNotification } from '../types'; | |
| import { Menu, X, Bell, Search, Globe, Shield, User as UserIcon, LogOut, LayoutDashboard, ChevronDown } from 'lucide-react'; | |
| import { TRANSLATIONS, Language } from '../translations'; | |
| interface HeaderProps { | |
| currentUser: User; | |
| onLogout: () => void; | |
| onLoginSimulate: () => void; | |
| currentView: string; | |
| setCurrentView: (view: string) => void; | |
| notifications: AppNotification[]; | |
| onMarkNotificationRead: (id: string) => void; | |
| onClearNotifications: () => void; | |
| onSearch: (query: string) => void; | |
| currentLanguage: string; | |
| setLanguage: (lang: any) => void; | |
| } | |
| const LANGUAGES = [ | |
| { code: 'UZ', name: "O'zbek" }, | |
| { code: 'RU', name: "Русский" }, | |
| { code: 'EN', name: "English" } | |
| ]; | |
| export const Header: React.FC<HeaderProps> = ({ | |
| currentUser, | |
| onLogout, | |
| onLoginSimulate, | |
| currentView, | |
| setCurrentView, | |
| notifications, | |
| onMarkNotificationRead, | |
| onClearNotifications, | |
| onSearch, | |
| currentLanguage, | |
| setLanguage, | |
| }) => { | |
| const [mobileMenuOpen, setMobileMenuOpen] = useState(false); | |
| const [notifDropdownOpen, setNotifDropdownOpen] = useState(false); | |
| const [langDropdownOpen, setLangDropdownOpen] = useState(false); | |
| const [searchString, setSearchString] = useState(''); | |
| const unreadNotifs = notifications.filter((n) => !n.read); | |
| const handleSearchSubmit = (e: React.FormEvent) => { | |
| e.preventDefault(); | |
| onSearch(searchString); | |
| }; | |
| const t = TRANSLATIONS[currentLanguage as Language] || TRANSLATIONS['EN']; | |
| const navItems = [ | |
| { id: 'home', label: t.navHome }, | |
| { id: 'register', label: t.navRegister }, | |
| { id: 'games', label: t.navGames }, | |
| { id: 'pro-league', label: t.navProLeague }, | |
| { id: 'results', label: t.navResults }, | |
| { id: 'profile', label: t.navProfile }, | |
| ]; | |
| return ( | |
| <header className="sticky top-0 z-40 bg-white/5 backdrop-blur-md border-b border-white/10 font-sans shadow-lg shadow-black/40"> | |
| <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> | |
| <div className="flex items-center justify-between h-20"> | |
| {/* Logo */} | |
| <div className="flex items-center gap-2 cursor-pointer" onClick={() => { setCurrentView('home'); setMobileMenuOpen(false); }}> | |
| <div className="w-10 h-10 rounded-xl bg-gradient-to-br from-cyan-400 to-purple-600 p-[1.5px] shadow-[0_0_15px_rgba(34,211,238,0.4)] active:scale-95 transition-transform"> | |
| <div className="w-full h-full bg-[#020205]/60 backdrop-blur-md rounded-[10px] flex items-center justify-center font-extrabold text-white text-lg tracking-wider font-mono"> | |
| <span className="text-cyan-400">N</span>E | |
| </div> | |
| </div> | |
| <div> | |
| <span className="text-lg font-black tracking-widest text-white uppercase font-mono bg-clip-text"> | |
| NOVA<span className="text-transparent bg-clip-text bg-gradient-to-r from-cyan-400 to-purple-500">ESPORTS</span> | |
| </span> | |
| <span className="block text-[9px] text-cyan-400 tracking-widest uppercase font-bold">{t.webPlatform}</span> | |
| </div> | |
| </div> | |
| {/* Desktop Navigation Links */} | |
| <nav className="hidden lg:flex space-x-1.5 xl:space-x-4"> | |
| {navItems.map((item) => ( | |
| <button | |
| key={item.id} | |
| onClick={() => { | |
| setCurrentView(item.id); | |
| setMobileMenuOpen(false); | |
| }} | |
| className={`px-3 py-2 rounded-lg text-xs font-bold tracking-wider uppercase transition-all duration-150 cursor-pointer ${ | |
| currentView === item.id | |
| ? 'bg-white/10 text-cyan-400 border border-white/20' | |
| : 'text-slate-300 hover:text-white hover:bg-white/5' | |
| }`} | |
| id={`nav-${item.id}`} | |
| > | |
| {item.label} | |
| </button> | |
| ))} | |
| {/* Quick Clan Navigation indicator */} | |
| {currentUser && currentUser.id !== 'guest' && ( | |
| <button | |
| onClick={() => { | |
| setCurrentView('clan'); | |
| setMobileMenuOpen(false); | |
| }} | |
| className={`px-3 py-2 rounded-lg text-xs font-bold tracking-wider uppercase transition-all duration-150 cursor-pointer flex items-center gap-1 border ${ | |
| currentView === 'clan' | |
| ? 'bg-purple-950/40 border-purple-500/50 text-purple-400' | |
| : 'text-purple-400/80 border-white/10 hover:text-purple-300 hover:bg-white/5' | |
| }`} | |
| id="nav-clan" | |
| > | |
| <Shield className="w-3.5 h-3.5" /> | |
| {currentLanguage === 'UZ' ? 'Klan Yaratish' : currentLanguage === 'RU' ? 'Создать клан' : 'Clan Alliance'} | |
| </button> | |
| )} | |
| </nav> | |
| {/* Right Header Toolbar (Search, Notifications, Lang, Auth) */} | |
| <div className="hidden lg:flex items-center space-x-3"> | |
| {/* Search Input Bar */} | |
| <form onSubmit={handleSearchSubmit} className="relative"> | |
| <input | |
| type="text" | |
| placeholder={t.searchPlaceholder} | |
| value={searchString} | |
| onChange={(e) => { | |
| setSearchString(e.target.value); | |
| onSearch(e.target.value); | |
| }} | |
| className="w-40 xl:w-52 bg-white/5 hover:bg-white/10 focus:bg-white/10 border border-white/10 hover:border-white/20 focus:border-cyan-400 rounded-lg pl-3 pr-8 py-1.5 text-xs text-white outline-none focus:ring-1 focus:ring-cyan-500/30 transition-all font-sans" | |
| /> | |
| <button type="submit" className="absolute right-2.5 top-2 text-slate-400 hover:text-white cursor-pointer"> | |
| <Search className="w-3.5 h-3.5" /> | |
| </button> | |
| </form> | |
| {/* Notification Trigger Dropdown */} | |
| <div className="relative"> | |
| <button | |
| onClick={() => { | |
| setNotifDropdownOpen(!notifDropdownOpen); | |
| setLangDropdownOpen(false); | |
| }} | |
| className="p-2 text-slate-300 hover:text-white rounded-lg bg-white/5 border border-white/10 hover:bg-white/10 transition-colors cursor-pointer relative" | |
| aria-label="Open notifications" | |
| id="header-notif-bell" | |
| > | |
| <Bell className="w-4 h-4" /> | |
| {unreadNotifs.length > 0 && ( | |
| <span className="absolute top-1.5 right-1.5 w-2 h-2 rounded-full bg-red-500 animate-ping" /> | |
| )} | |
| </button> | |
| {/* Notification Box */} | |
| {notifDropdownOpen && ( | |
| <div className="absolute right-0 mt-2.5 w-80 bg-slate-950/80 border border-white/10 rounded-xl shadow-2xl overflow-hidden backdrop-blur-md z-50 animate-in fade-in slide-in-from-top-2 duration-150"> | |
| <div className="p-3 bg-white/5 border-b border-white/10 flex justify-between items-center"> | |
| <span className="text-xs font-bold text-white tracking-wider font-mono">{t.telemetryTitle}</span> | |
| {notifications.length > 0 && ( | |
| <button | |
| onClick={onClearNotifications} | |
| className="text-[10px] text-cyan-400 hover:text-cyan-300 transition-colors font-bold uppercase" | |
| > | |
| {t.flushAll} | |
| </button> | |
| )} | |
| </div> | |
| <div className="max-h-60 overflow-y-auto divide-y divide-white/10 custom-scrollbar"> | |
| {notifications.length === 0 ? ( | |
| <div className="p-6 text-center text-slate-500 text-xs">{t.noNotifs}</div> | |
| ) : ( | |
| notifications.map((notif) => ( | |
| <div | |
| key={notif.id} | |
| onClick={() => onMarkNotificationRead(notif.id)} | |
| className={`p-3 text-left transition-colors cursor-pointer hover:bg-white/5 ${ | |
| !notif.read ? 'bg-cyan-400/10 border-l-2 border-cyan-400' : '' | |
| }`} | |
| > | |
| <div className="flex justify-between items-start gap-1"> | |
| <span className="text-[11px] font-bold text-white">{notif.title}</span> | |
| <span className="text-[9px] text-slate-500 shrink-0">{notif.time}</span> | |
| </div> | |
| <p className="text-[11px] text-slate-400 mt-1 font-sans">{notif.message}</p> | |
| </div> | |
| )) | |
| )} | |
| </div> | |
| </div> | |
| )} | |
| </div> | |
| {/* Language Selector Dropdown */} | |
| <div className="relative"> | |
| <button | |
| onClick={() => { | |
| setLangDropdownOpen(!langDropdownOpen); | |
| setNotifDropdownOpen(false); | |
| }} | |
| className="px-2.5 py-1.5 text-xs text-slate-300 hover:text-white rounded-lg bg-white/5 border border-white/10 flex items-center gap-1.5 hover:bg-white/10 transition-colors cursor-pointer" | |
| id="header-lang-trigger" | |
| > | |
| <Globe className="w-3.5 h-3.5" /> | |
| <span className="font-mono font-bold leading-none">{currentLanguage}</span> | |
| <ChevronDown className="w-3 h-3 text-slate-500" /> | |
| </button> | |
| {langDropdownOpen && ( | |
| <div className="absolute right-0 mt-2 w-32 bg-slate-950/80 border border-white/10 rounded-lg shadow-xl backdrop-blur-md overflow-hidden z-50"> | |
| <div className="py-1"> | |
| {LANGUAGES.map((lang) => ( | |
| <button | |
| key={lang.code} | |
| onClick={() => { | |
| setLanguage(lang.code); | |
| setLangDropdownOpen(false); | |
| }} | |
| className={`w-full text-left px-3 py-1.5 text-xs transition-colors flex items-center justify-between cursor-pointer ${ | |
| currentLanguage === lang.code ? 'text-cyan-400 bg-white/10 font-bold' : 'text-slate-300 hover:text-white hover:bg-white/5' | |
| }`} | |
| > | |
| <span>{lang.name}</span> | |
| <span className="text-[9px] font-mono text-slate-500">{lang.code}</span> | |
| </button> | |
| ))} | |
| </div> | |
| </div> | |
| )} | |
| </div> | |
| {/* User Profile Avatar / Action Button */} | |
| {currentUser ? ( | |
| <div | |
| onClick={() => setCurrentView('profile')} | |
| className="flex items-center gap-2.5 pl-2.5 border-l border-white/15 py-1 hover:opacity-90 cursor-pointer" | |
| > | |
| <div className="text-right"> | |
| <span className="block text-xs font-bold text-slate-200 tracking-wide">{currentUser.username}</span> | |
| <span className="block text-[10px] text-cyan-400 font-mono font-semibold">{currentUser.points} {t.playPoints}</span> | |
| </div> | |
| <div className="w-9 h-9 rounded-full bg-gradient-to-br from-cyan-400 to-purple-600 flex items-center justify-center text-sm font-bold shadow-md shadow-purple-600/15 overflow-hidden"> | |
| {currentUser.avatar && (currentUser.avatar.startsWith('http://') || currentUser.avatar.startsWith('https://')) ? ( | |
| <img src={currentUser.avatar} className="w-full h-full object-cover rounded-full" alt="avatar" referrerPolicy="no-referrer" /> | |
| ) : ( | |
| <span>{currentUser.avatar || '👤'}</span> | |
| )} | |
| </div> | |
| </div> | |
| ) : ( | |
| <button | |
| onClick={onLoginSimulate} | |
| className="bg-gradient-to-r from-cyan-600 to-cyan-500 text-white font-bold px-4 py-2 rounded-lg text-xs uppercase tracking-wide cursor-pointer transition-transform duration-100 hover:scale-105" | |
| > | |
| {t.gamerIn} | |
| </button> | |
| )} | |
| </div> | |
| {/* Mobile menu trigger */} | |
| <div className="flex items-center lg:hidden gap-3"> | |
| {/* Quick Notify Bell for Mobile */} | |
| <div className="relative"> | |
| <button | |
| onClick={() => setCurrentView('profile')} | |
| className="p-1.5 text-slate-300 hover:text-white rounded bg-white/5 border border-white/10 hover:bg-white/10" | |
| > | |
| <span className="relative inline-block"> | |
| <Bell className="w-4 h-4" /> | |
| {unreadNotifs.length > 0 && ( | |
| <span className="absolute -top-1 -right-1 w-2 h-2 rounded-full bg-red-500 shrink-0" /> | |
| )} | |
| </span> | |
| </button> | |
| </div> | |
| <button | |
| onClick={() => setMobileMenuOpen(!mobileMenuOpen)} | |
| className="text-slate-300 hover:text-inherit p-2 rounded transition-colors bg-white/5 border border-white/10 hover:bg-white/10 cursor-pointer" | |
| aria-label="Toggle Menu" | |
| > | |
| {mobileMenuOpen ? <X className="w-6 h-6" /> : <Menu className="w-6 h-6" />} | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| {/* Mobile Drawer Navigation overlay */} | |
| {mobileMenuOpen && ( | |
| <div className="lg:hidden bg-slate-950/80 backdrop-blur-md border-b border-white/10 p-5 space-y-4 animate-in fade-in duration-200"> | |
| <form onSubmit={handleSearchSubmit} className="relative"> | |
| <input | |
| type="text" | |
| placeholder={t.searchPlaceholder} | |
| value={searchString} | |
| onChange={(e) => { | |
| setSearchString(e.target.value); | |
| onSearch(e.target.value); | |
| }} | |
| className="w-full bg-white/5 border border-white/10 rounded-lg pl-3 pr-8 py-2 text-xs text-white outline-none focus:border-cyan-400" | |
| /> | |
| <button type="submit" className="absolute right-3 top-2.5 text-slate-400"> | |
| <Search className="w-4 h-4" /> | |
| </button> | |
| </form> | |
| <div className="flex flex-col space-y-2"> | |
| {navItems.map((item) => ( | |
| <button | |
| key={item.id} | |
| onClick={() => { | |
| setCurrentView(item.id); | |
| setMobileMenuOpen(false); | |
| }} | |
| className={`py-2 px-3 text-left rounded-lg text-xs font-bold tracking-wider uppercase transition-colors ${ | |
| currentView === item.id | |
| ? 'bg-white/10 text-cyan-400 border-l-4 border-cyan-400' | |
| : 'text-slate-300 hover:bg-white/5' | |
| }`} | |
| > | |
| {item.label} | |
| </button> | |
| ))} | |
| {currentUser && currentUser.id !== 'guest' && ( | |
| <button | |
| onClick={() => { | |
| setCurrentView('clan'); | |
| setMobileMenuOpen(false); | |
| }} | |
| className={`py-2 px-3 text-left rounded-lg text-xs font-bold tracking-wider uppercase text-purple-400 flex items-center gap-1.5 ${ | |
| currentView === 'clan' ? 'bg-purple-950/40 border-l-4 border-purple-500' : '' | |
| }`} | |
| > | |
| <Shield className="w-3.5 h-3.5" /> | |
| {currentLanguage === 'UZ' ? 'Klan Yaratish' : currentLanguage === 'RU' ? 'Создать клан' : 'Clan Alliance'} | |
| </button> | |
| )} | |
| </div> | |
| <div className="border-t border-white/10 pt-4 flex items-center justify-between"> | |
| {currentUser ? ( | |
| <div className="flex items-center gap-2.5"> | |
| <div className="w-8 h-8 rounded-full bg-cyan-600 flex items-center justify-center text-xs font-bold text-white overflow-hidden"> | |
| {currentUser.avatar && (currentUser.avatar.startsWith('http://') || currentUser.avatar.startsWith('https://')) ? ( | |
| <img src={currentUser.avatar} className="w-full h-full object-cover rounded-full" alt="avatar" referrerPolicy="no-referrer" /> | |
| ) : ( | |
| <span>{currentUser.avatar || '👤'}</span> | |
| )} | |
| </div> | |
| <div> | |
| <span className="block text-xs font-bold text-white">{currentUser.username}</span> | |
| <span className="block text-[10px] text-cyan-450 text-cyan-400 font-mono font-semibold">{currentUser.points} {t.playPoints}</span> | |
| </div> | |
| </div> | |
| ) : ( | |
| <button | |
| onClick={() => { | |
| onLoginSimulate(); | |
| setMobileMenuOpen(false); | |
| }} | |
| className="w-full bg-cyan-600 text-white font-bold py-2 rounded text-xs uppercase" | |
| > | |
| {t.gamerIn} | |
| </button> | |
| )} | |
| <div className="flex gap-2"> | |
| <button | |
| onClick={() => { | |
| const nextLang = currentLanguage === 'EN' ? 'UZ' : currentLanguage === 'UZ' ? 'RU' : 'EN'; | |
| setLanguage(nextLang); | |
| }} | |
| className="px-2 py-1 bg-white/5 border border-white/10 rounded text-[10px] text-slate-300 font-mono" | |
| > | |
| LANG: {currentLanguage} | |
| </button> | |
| {currentUser && ( | |
| <button | |
| onClick={() => { | |
| onLogout(); | |
| setMobileMenuOpen(false); | |
| }} | |
| className="p-1 px-2.5 bg-white/5 border border-white/10 hover:bg-white/10 text-slate-400 hover:text-white rounded flex items-center gap-1 text-[10px]" | |
| > | |
| <LogOut className="w-3 h-3" /> {t.exit} | |
| </button> | |
| )} | |
| </div> | |
| </div> | |
| </div> | |
| )} | |
| </header> | |
| ); | |
| }; | |