Spaces:
Sleeping
Sleeping
Download src/components/Header.tsx from vooom/NewsAnalyze: direct link, hf CLI and curl.
- Browser
- Download file 8.64 kB
-
https://huggingface.co/spaces/vooom/NewsAnalyze/resolve/main/src/components/Header.tsx
- Command line
-
hf download hf://spaces/vooom/NewsAnalyze/src/components/Header.tsx
-
curl -L -o Header.tsx https://huggingface.co/spaces/vooom/NewsAnalyze/resolve/main/src/components/Header.tsx
8.64 kB
| import React, { useState, useEffect } from "react"; | |
| import { Activity, Database, Terminal, FileText, ShieldCheck, Settings, User as UserIcon, LogOut, Menu, X, Globe, Radio } from "lucide-react"; | |
| import { auth, signOut, onAuthStateChanged, User } from "../config/firebase.js"; | |
| import { useLanguage } from "../context/LanguageContext.js"; | |
| export type NavTab = "forecast" | "wire" | "connectors" | "sandbox" | "documents" | "audit"; | |
| interface HeaderProps { | |
| activeTab: NavTab; | |
| setActiveTab: (tab: NavTab) => void; | |
| onNewForecastClick: () => void; | |
| onOpenAuthModal: () => void; | |
| onOpenSettingsModal: () => void; | |
| } | |
| export const Header: React.FC<HeaderProps> = ({ | |
| activeTab, | |
| setActiveTab, | |
| onNewForecastClick, | |
| onOpenAuthModal, | |
| onOpenSettingsModal, | |
| }) => { | |
| const [currentUser, setCurrentUser] = useState<User | null>(null); | |
| const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); | |
| const { language, toggleLanguage, t } = useLanguage(); | |
| const isArabic = language === "ar"; | |
| useEffect(() => { | |
| const unsubscribe = onAuthStateChanged(auth, (user) => { | |
| setCurrentUser(user); | |
| }); | |
| return () => unsubscribe(); | |
| }, []); | |
| const navItems: Array<{ id: NavTab; label: string; icon: any; color: string; live?: boolean }> = [ | |
| { id: "forecast", label: t.nav.forecast, icon: Activity, color: "text-cyan-400" }, | |
| { id: "wire", label: isArabic ? "رصد الأخبار الحية" : "Live News Wire", icon: Radio, color: "text-rose-400", live: true }, | |
| { id: "connectors", label: t.nav.connectors, icon: Database, color: "text-emerald-400" }, | |
| { id: "sandbox", label: t.nav.sandbox, icon: Terminal, color: "text-amber-400" }, | |
| { id: "documents", label: t.nav.documents, icon: FileText, color: "text-purple-400" }, | |
| { id: "audit", label: t.nav.audit, icon: ShieldCheck, color: "text-sky-400" }, | |
| ]; | |
| const handleTabClick = (tabId: NavTab) => { | |
| setActiveTab(tabId); | |
| setIsMobileMenuOpen(false); | |
| }; | |
| return ( | |
| <header className="bg-slate-900/90 border-b border-slate-800 backdrop-blur-md sticky top-0 z-40 w-full overflow-x-hidden"> | |
| <div className="max-w-7xl mx-auto px-4 sm:px-6 py-3 flex items-center justify-between gap-3"> | |
| {/* Zone 1: Wordmark */} | |
| <div className="flex items-center gap-2.5 shrink-0"> | |
| <div className="w-8 h-8 rounded-lg bg-cyan-500/10 border border-cyan-500/30 flex items-center justify-center text-cyan-400 font-mono font-bold text-sm shadow-inner shrink-0"> | |
| GS | |
| </div> | |
| <button | |
| onClick={() => handleTabClick("forecast")} | |
| className="text-sm sm:text-base font-bold tracking-tight text-white whitespace-nowrap shrink-0 flex items-center gap-1.5 font-display hover:text-cyan-300 transition-colors cursor-pointer text-left rtl:text-right" | |
| > | |
| {t.appName} <span className="text-slate-500 font-mono text-xs font-normal hidden sm:inline">{t.appSubtitle}</span> | |
| </button> | |
| </div> | |
| {/* Zone 2: Desktop Navigation Bar */} | |
| <nav className="hidden lg:flex items-center gap-1 p-1 bg-slate-950/60 rounded-lg border border-slate-800/80"> | |
| {navItems.map((item) => { | |
| const Icon = item.icon; | |
| const isActive = activeTab === item.id; | |
| return ( | |
| <button | |
| key={item.id} | |
| onClick={() => handleTabClick(item.id)} | |
| className={`flex items-center gap-2 px-3 py-1.5 text-xs font-medium rounded-md transition-all whitespace-nowrap shrink-0 cursor-pointer ${ | |
| isActive | |
| ? "bg-slate-800 text-cyan-300 shadow-sm border border-slate-700/60 font-semibold" | |
| : "text-slate-400 hover:text-slate-200 hover:bg-slate-900/40" | |
| }`} | |
| > | |
| <span className="relative flex items-center"> | |
| <Icon className={`w-3.5 h-3.5 ${item.color}`} /> | |
| {item.live && ( | |
| <span className="absolute -top-1 -right-1 flex h-2 w-2"> | |
| <span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-rose-400 opacity-75"></span> | |
| <span className="relative inline-flex rounded-full h-2 w-2 bg-rose-500"></span> | |
| </span> | |
| )} | |
| </span> | |
| <span>{item.label}</span> | |
| </button> | |
| ); | |
| })} | |
| </nav> | |
| {/* Zone 3: Actions & User Profile */} | |
| <div className="flex items-center gap-2 shrink-0"> | |
| {/* Language Switcher */} | |
| <button | |
| onClick={toggleLanguage} | |
| title={language === "en" ? "التبديل إلى العربية" : "Switch to English"} | |
| className="px-2.5 py-1.5 bg-slate-800 hover:bg-slate-700 text-cyan-300 hover:text-cyan-200 text-xs font-semibold rounded-lg border border-slate-700 transition-colors flex items-center gap-1.5 shrink-0 cursor-pointer" | |
| > | |
| <Globe className="w-3.5 h-3.5 text-cyan-400 shrink-0" /> | |
| <span className="font-mono">{language === "en" ? "العربية" : "EN"}</span> | |
| </button> | |
| <button | |
| onClick={onOpenSettingsModal} | |
| title={t.nav.settings} | |
| className="p-2 bg-slate-800 hover:bg-slate-700 text-slate-300 hover:text-white rounded-lg transition-colors border border-slate-700 shrink-0 cursor-pointer" | |
| > | |
| <Settings className="w-4 h-4" /> | |
| </button> | |
| {currentUser ? ( | |
| <div className="flex items-center gap-2"> | |
| <div className="hidden sm:flex items-center gap-2 px-2.5 py-1 bg-slate-800/80 rounded-lg border border-slate-700"> | |
| <UserIcon className="w-3.5 h-3.5 text-cyan-400" /> | |
| <span className="text-xs font-mono text-slate-200 truncate max-w-[120px]"> | |
| {currentUser.displayName || currentUser.email?.split("@")[0] || "Strategist"} | |
| </span> | |
| </div> | |
| <button | |
| onClick={() => signOut(auth)} | |
| title={t.nav.signOut} | |
| className="p-2 bg-slate-800 hover:bg-rose-950/40 text-slate-400 hover:text-rose-400 rounded-lg transition-colors border border-slate-700 shrink-0 cursor-pointer" | |
| > | |
| <LogOut className="w-4 h-4" /> | |
| </button> | |
| </div> | |
| ) : ( | |
| <button | |
| onClick={onOpenAuthModal} | |
| className="px-3 py-1.5 bg-cyan-500 hover:bg-cyan-400 text-slate-950 font-bold text-xs rounded-lg transition-all flex items-center gap-1.5 shadow-sm shrink-0 cursor-pointer" | |
| > | |
| <UserIcon className="w-3.5 h-3.5" /> | |
| <span className="hidden sm:inline">{t.nav.signIn}</span> | |
| </button> | |
| )} | |
| {/* Mobile Menu Toggle Button */} | |
| <button | |
| onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)} | |
| className="lg:hidden p-2 bg-slate-800 text-slate-300 hover:text-white rounded-lg border border-slate-700 shrink-0 cursor-pointer" | |
| aria-label="Toggle menu" | |
| > | |
| {isMobileMenuOpen ? <X className="w-4 h-4" /> : <Menu className="w-4 h-4" />} | |
| </button> | |
| </div> | |
| </div> | |
| {/* Mobile Navigation Drawer */} | |
| {isMobileMenuOpen && ( | |
| <div className="lg:hidden border-t border-slate-800 bg-slate-900/95 px-4 py-3 space-y-1 backdrop-blur-md"> | |
| {navItems.map((item) => { | |
| const Icon = item.icon; | |
| const isActive = activeTab === item.id; | |
| return ( | |
| <button | |
| key={item.id} | |
| onClick={() => handleTabClick(item.id)} | |
| className={`w-full flex items-center justify-between px-3 py-2 text-xs font-medium rounded-lg transition-all ${ | |
| isActive | |
| ? "bg-slate-800 text-cyan-300 font-semibold border border-slate-700/60" | |
| : "text-slate-400 hover:text-slate-200 hover:bg-slate-800/40" | |
| }`} | |
| > | |
| <div className="flex items-center gap-2.5"> | |
| <Icon className={`w-4 h-4 ${item.color}`} /> | |
| <span>{item.label}</span> | |
| </div> | |
| {item.live && ( | |
| <span className="text-[10px] font-mono text-rose-400 bg-rose-950/80 px-2 py-0.5 rounded border border-rose-800"> | |
| LIVE | |
| </span> | |
| )} | |
| </button> | |
| ); | |
| })} | |
| </div> | |
| )} | |
| </header> | |
| ); | |
| }; | |