Spaces:
Sleeping
Sleeping
Download frontend/components/MobileNav.tsx from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 9.02 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/frontend/components/MobileNav.tsx
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/frontend/components/MobileNav.tsx
-
curl -L -o MobileNav.tsx https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/frontend/components/MobileNav.tsx
9.02 kB
| 'use client' | |
| import { useState, useEffect } from 'react' | |
| import { createPortal } from 'react-dom' | |
| import { Menu, X, User, Settings, LogOut, ChevronDown, Search, Flame } from 'lucide-react' | |
| import { motion, AnimatePresence } from 'framer-motion' | |
| import { usePathname } from 'next/navigation' | |
| import { Shield } from 'lucide-react' | |
| import Link from 'next/link' | |
| import { useAuth } from '@/contexts/AuthContext' | |
| import { api } from '@/lib/api' | |
| import { cn } from '@/lib/utils' | |
| export function MobileHeader({ onOpen }: { onOpen?: () => void }) { | |
| const { user, logout } = useAuth() | |
| const [companyName, setCompanyName] = useState<string | null>(null) | |
| const [usageStats, setUsageStats] = useState<{ | |
| plan: string | |
| conversations_used: number | |
| conversations_limit: number | null | |
| } | null>(null) | |
| const [showProfileMenu, setShowProfileMenu] = useState(false) | |
| // Load usage stats | |
| useEffect(() => { | |
| const loadUsage = async () => { | |
| try { | |
| const [usageRes, tenantRes] = await Promise.all([ | |
| api.get('/api/v1/tenants/me/usage'), | |
| api.get('/api/v1/tenants/me') | |
| ]) | |
| setUsageStats(usageRes.data) | |
| setCompanyName(tenantRes.data.company_name || null) | |
| } catch (e) { | |
| console.error('Failed to load usage or tenant') | |
| } | |
| } | |
| if (user) loadUsage() | |
| }, [user]) | |
| // Get user initials for avatar | |
| const getInitials = (name?: string | null, email?: string) => { | |
| if (name) return name.split(' ').map(n => n[0]).join('').toUpperCase().slice(0, 2) | |
| if (email) return email.slice(0, 2).toUpperCase() | |
| return 'U' | |
| } | |
| const getAvatarColor = (email?: string) => { | |
| if (!email) return 'bg-indigo-600' | |
| const colors = ['bg-indigo-600', 'bg-purple-600', 'bg-pink-600', 'bg-blue-600'] | |
| return colors[email.charCodeAt(0) % colors.length] | |
| } | |
| const usedDialogs = usageStats?.conversations_used || 0 | |
| const limitDialogs = usageStats?.conversations_limit | |
| const isUnlimited = limitDialogs === null || limitDialogs === undefined | |
| return ( | |
| <div className="flex flex-col fixed top-[-1px] left-0 right-0 z-[60] bg-gradient-to-b from-black via-[#050510]/95 to-[#050510]/80 backdrop-blur-xl border-b border-white/5 pt-[calc(env(safe-area-inset-top,0px)+1px)] md:hidden"> | |
| <div className="flex items-center justify-between px-3 h-[52px] text-white w-full relative"> | |
| {/* Left: Logo + Brand Name */} | |
| <Link href="/settings/brain" className="flex items-center gap-2.5 active:scale-95 transition-transform"> | |
| <div className="w-7 h-7 relative"> | |
| <img src="/logo-v2.png" alt="Logo" className="w-full h-full object-contain relative z-10" /> | |
| </div> | |
| <span className="font-bold text-base tracking-[0.18em] uppercase text-white"> | |
| MICROFUNNEL | |
| </span> | |
| </Link> | |
| {/* Right: Hub */} | |
| <div className="flex items-center gap-2"> | |
| {usageStats && ( | |
| <div className="hidden sm:block text-[9px] font-bold text-indigo-400 bg-indigo-500/10 px-2 py-0.5 rounded-full border border-indigo-500/20 uppercase tracking-tighter"> | |
| {usedDialogs}/{isUnlimited ? '∞' : limitDialogs} | |
| </div> | |
| )} | |
| {/* Profile avatar and menu */} | |
| <UserMenu user={user} logout={logout} companyName={companyName} getInitials={getInitials} getAvatarColor={getAvatarColor} /> | |
| </div> | |
| </div> | |
| </div> | |
| ) | |
| } | |
| function UserMenu({ user, logout, companyName, getInitials, getAvatarColor }: any) { | |
| return ( | |
| <div className="flex items-center gap-1.5"> | |
| <Link | |
| href="/settings/account" | |
| className="flex items-center gap-2 p-0.5 pr-2 rounded-full hover:bg-white/5 active:bg-white/10 transition-all border border-transparent hover:border-white/5" | |
| > | |
| <div | |
| className={cn( | |
| "w-7 h-7 rounded-full flex items-center justify-center text-white font-bold text-[10px] border border-white/10 shadow-sm overflow-hidden", | |
| !user?.avatar_url && getAvatarColor(user?.email) | |
| )} | |
| > | |
| {user?.avatar_url ? ( | |
| <img src={user.avatar_url} alt="Avatar" className="w-full h-full object-cover" /> | |
| ) : ( | |
| getInitials(user?.full_name, user?.email) | |
| )} | |
| </div> | |
| <div className="hidden min-[400px]:flex flex-col items-start"> | |
| <span className="text-[10px] font-bold text-white leading-none whitespace-nowrap truncate max-w-[80px]"> | |
| {companyName || user?.full_name || 'User'} | |
| </span> | |
| </div> | |
| </Link> | |
| <div className="w-px h-4 bg-white/10 mx-0.5" /> | |
| <button | |
| onClick={() => logout()} | |
| className="p-1.5 text-slate-400 hover:text-red-400 active:text-red-500 transition-colors rounded-lg active:bg-white/5" | |
| title="Выйти" | |
| > | |
| <LogOut className="w-4.5 h-4.5" /> | |
| </button> | |
| </div> | |
| ) | |
| } | |
| export function MobileSidebarWrapper({ children }: { children: React.ReactNode }) { | |
| const [isOpen, setIsOpen] = useState(false) | |
| const pathname = usePathname() | |
| useEffect(() => { | |
| const handleToggle = () => setIsOpen(prev => !prev) | |
| document.addEventListener('toggle-mobile-sidebar', handleToggle) | |
| return () => document.removeEventListener('toggle-mobile-sidebar', handleToggle) | |
| }, []) | |
| // Lock body scroll when sidebar is open | |
| useEffect(() => { | |
| if (isOpen) { | |
| document.body.style.overflow = 'hidden' | |
| // Also try to lock the main content if possible | |
| const mainContent = document.querySelector('main') | |
| if (mainContent) mainContent.style.overflow = 'hidden' | |
| } else { | |
| document.body.style.overflow = '' | |
| const mainContent = document.querySelector('main') | |
| if (mainContent) mainContent.style.overflow = '' | |
| } | |
| return () => { | |
| document.body.style.overflow = '' | |
| const mainContent = document.querySelector('main') | |
| if (mainContent) mainContent.style.overflow = '' | |
| } | |
| }, [isOpen]) | |
| // Close on route change | |
| useEffect(() => { | |
| setIsOpen(false) | |
| document.dispatchEvent(new CustomEvent('close-mobile-sidebar')) | |
| }, [pathname]) | |
| const closeSidebar = () => { | |
| setIsOpen(false) | |
| document.dispatchEvent(new CustomEvent('close-mobile-sidebar')) | |
| } | |
| return ( | |
| <div className="lg:hidden"> | |
| <AnimatePresence> | |
| {isOpen && ( | |
| <> | |
| {/* Backdrop */} | |
| <motion.div | |
| initial={{ opacity: 0 }} | |
| animate={{ opacity: 1 }} | |
| exit={{ opacity: 0 }} | |
| onClick={closeSidebar} | |
| className="fixed inset-0 bg-black/30 backdrop-blur-sm z-40" | |
| /> | |
| {/* Sidebar Drawer */} | |
| <motion.div | |
| initial={{ x: '-100%' }} | |
| animate={{ x: 0 }} | |
| exit={{ x: '-100%' }} | |
| transition={{ type: 'spring', damping: 25, stiffness: 200 }} | |
| className="fixed left-0 top-0 bottom-0 w-72 backdrop-blur-3xl z-50 shadow-2xl overflow-hidden border-r border-white/10" | |
| style={{ | |
| background: 'rgba(5, 5, 16, 0.85)', | |
| }} | |
| > | |
| {/* Aurora Effect Background */} | |
| <div className="absolute inset-0 overflow-hidden pointer-events-none z-0"> | |
| <div className="absolute top-[-10%] left-[-10%] w-[50%] h-[30%] rounded-full bg-indigo-500/10 blur-[60px]" /> | |
| <div className="absolute bottom-[-10%] right-[-10%] w-[50%] h-[30%] rounded-full bg-purple-500/10 blur-[60px]" /> | |
| </div> | |
| <div className="relative z-10 h-full pt-[calc(52px+env(safe-area-inset-top,0px))]"> | |
| {children} | |
| </div> | |
| </motion.div> | |
| </> | |
| )} | |
| </AnimatePresence> | |
| </div> | |
| ) | |
| } | |