Spaces:
Runtime error
Runtime error
File size: 9,193 Bytes
2a60e5d 108f7fe 2a60e5d 108f7fe d46fdda 3aaed2e 2a60e5d 108f7fe 2a60e5d 108f7fe 3aaed2e 108f7fe d46fdda 108f7fe d46fdda 108f7fe d46fdda 108f7fe d46fdda 108f7fe 2a60e5d 108f7fe 2a60e5d 108f7fe 2a60e5d 108f7fe 2a60e5d 108f7fe 2a60e5d 108f7fe 2a60e5d 108f7fe 2a60e5d 108f7fe 2a60e5d 108f7fe 2a60e5d 108f7fe 2a60e5d 108f7fe 2a60e5d 108f7fe 2a60e5d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | import React, { useState } from 'react';
import { Outlet, NavLink, useNavigate } from 'react-router-dom';
import { useAuthStore } from '../utils/store';
import { useTheme } from './ThemeProvider';
import {
LayoutDashboard,
Briefcase,
TrendingUp,
TrendingDown,
Flame,
Bell,
LogOut,
Menu,
X,
ChevronDown,
User,
Eye,
ArrowLeftRight,
BarChart3,
Target,
DollarSign,
Newspaper,
Brain,
ArrowRightLeft,
Trophy,
GitCompare,
Share2,
Gauge,
Sun,
Moon,
FileDown,
Shield,
SlidersHorizontal,
Calculator,
FileText,
Scale,
Zap,
Search,
BarChart2
} from 'lucide-react';
const Layout = () => {
const [sidebarOpen, setSidebarOpen] = useState(false);
const [userMenuOpen, setUserMenuOpen] = useState(false);
const { user, logout } = useAuthStore();
const { theme, toggleTheme } = useTheme();
const navigate = useNavigate();
const handleLogout = () => {
logout();
navigate('/login');
};
const navSections = [
{
title: 'Invest',
items: [
{ path: '/top-picks', icon: Zap, label: 'Top Picks Today' },
{ path: '/invest/analyze', icon: Search, label: 'Deep Analysis' },
{ path: '/market-pulse', icon: BarChart2, label: 'Market Pulse' },
{ path: '/profit-calc', icon: Calculator, label: 'Profit Calculator' },
]
},
{
title: 'Portfolio',
items: [
{ path: '/dashboard', icon: LayoutDashboard, label: 'Dashboard' },
{ path: '/portfolio', icon: Briefcase, label: 'Portfolio' },
{ path: '/analytics', icon: BarChart3, label: 'Analytics' },
{ path: '/risk', icon: Shield, label: 'Risk Analysis' },
{ path: '/rebalance', icon: Scale, label: 'Rebalance' },
]
},
{
title: 'Markets',
items: [
{ path: '/markets', icon: TrendingUp, label: 'Markets' },
{ path: '/watchlist', icon: Eye, label: 'Watchlist' },
{ path: '/screener', icon: SlidersHorizontal, label: 'Screener' },
{ path: '/gainers', icon: Flame, label: 'Top Gainers' },
{ path: '/losers', icon: TrendingDown, label: 'Top Losers' },
{ path: '/news', icon: Newspaper, label: 'News Feed' },
{ path: '/fear-greed', icon: Gauge, label: 'Fear & Greed' },
]
},
{
title: 'Tools',
items: [
{ path: '/prediction', icon: Brain, label: 'AI Prediction' },
{ path: '/dca', icon: Calculator, label: 'DCA Calculator' },
{ path: '/converter', icon: ArrowRightLeft, label: 'Converter' },
{ path: '/alerts', icon: Bell, label: 'Alerts' },
{ path: '/compare', icon: GitCompare, label: 'Compare' },
]
},
{
title: 'Finance',
items: [
{ path: '/transactions', icon: ArrowLeftRight, label: 'Transactions' },
{ path: '/tax-report', icon: FileText, label: 'Tax Report' },
{ path: '/goals', icon: Target, label: 'Goals' },
{ path: '/dividends', icon: DollarSign, label: 'Dividends' },
]
},
{
title: 'Social',
items: [
{ path: '/leaderboard', icon: Trophy, label: 'Leaderboard' },
{ path: '/share', icon: Share2, label: 'Share Portfolio' },
]
},
];
return (
<div className="min-h-screen flex">
{/* Sidebar */}
<aside className={`
fixed inset-y-0 left-0 z-50 w-64 bg-dark-300 border-r border-white/5
transform transition-transform duration-300 ease-in-out overflow-y-auto
lg:translate-x-0 lg:static lg:inset-auto
${sidebarOpen ? 'translate-x-0' : '-translate-x-full'}
`}>
{/* Logo */}
<div className="h-16 flex items-center justify-between px-6 border-b border-white/5 sticky top-0 bg-dark-300 z-10">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-gradient-to-br from-primary-500 to-success-500 flex items-center justify-center">
<TrendingUp className="w-6 h-6 text-white" />
</div>
<span className="font-bold text-xl">CryptoStock</span>
</div>
<button
className="lg:hidden text-gray-400 hover:text-white"
onClick={() => setSidebarOpen(false)}
>
<X className="w-6 h-6" />
</button>
</div>
{/* Navigation */}
<nav className="p-4 space-y-6 pb-24">
{navSections.map((section) => (
<div key={section.title}>
<p className="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-2 px-4">
{section.title}
</p>
<div className="space-y-1">
{section.items.map(({ path, icon: Icon, label }) => (
<NavLink
key={path}
to={path}
onClick={() => setSidebarOpen(false)}
className={({ isActive }) => `
flex items-center gap-3 px-4 py-2.5 rounded-xl transition-all duration-200 text-sm
${isActive
? 'bg-primary-500/20 text-primary-400 border border-primary-500/30'
: 'text-gray-400 hover:bg-white/5 hover:text-white'
}
`}
>
<Icon className="w-4 h-4" />
<span className="font-medium">{label}</span>
</NavLink>
))}
</div>
</div>
))}
</nav>
{/* User Section */}
<div className="absolute bottom-0 left-0 right-0 p-4 border-t border-white/5 bg-dark-300">
<div className="flex items-center gap-3 px-4 py-3 rounded-xl bg-white/5">
<div className="w-10 h-10 rounded-full bg-gradient-to-br from-primary-500 to-purple-500 flex items-center justify-center">
<User className="w-5 h-5 text-white" />
</div>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium truncate">{user?.full_name || user?.username}</p>
<p className="text-xs text-gray-400 truncate">{user?.email}</p>
</div>
</div>
</div>
</aside>
{/* Main Content */}
<div className="flex-1 flex flex-col min-h-screen">
{/* Header */}
<header className="h-16 flex items-center justify-between px-4 lg:px-8 border-b border-white/5 bg-dark-300/50 backdrop-blur-xl sticky top-0 z-40">
<button
className="lg:hidden text-gray-400 hover:text-white"
onClick={() => setSidebarOpen(true)}
>
<Menu className="w-6 h-6" />
</button>
<div className="hidden lg:flex items-center gap-2 text-sm text-gray-400">
<span>Press</span>
<kbd className="px-2 py-1 bg-white/10 rounded-md text-xs font-mono">Ctrl+K</kbd>
<span>to search</span>
</div>
{/* Right side */}
<div className="flex items-center gap-3 ml-auto">
{/* Theme Toggle */}
<button
onClick={toggleTheme}
className="p-2 text-gray-400 hover:text-white transition-colors rounded-lg hover:bg-white/5"
>
{theme === 'dark' ? <Sun className="w-5 h-5" /> : <Moon className="w-5 h-5" />}
</button>
{/* Notifications */}
<button className="relative p-2 text-gray-400 hover:text-white transition-colors">
<Bell className="w-5 h-5" />
<span className="absolute top-1 right-1 w-2 h-2 bg-danger-500 rounded-full"></span>
</button>
{/* User Menu */}
<div className="relative">
<button
onClick={() => setUserMenuOpen(!userMenuOpen)}
className="flex items-center gap-2 text-gray-400 hover:text-white transition-colors"
>
<div className="w-8 h-8 rounded-full bg-gradient-to-br from-primary-500 to-purple-500 flex items-center justify-center">
<User className="w-4 h-4 text-white" />
</div>
<ChevronDown className="w-4 h-4" />
</button>
{userMenuOpen && (
<div className="absolute right-0 mt-2 w-48 glass-card py-2 animate-fade-in">
<button
onClick={handleLogout}
className="w-full flex items-center gap-2 px-4 py-2 text-gray-400 hover:text-white hover:bg-white/5 transition-colors"
>
<LogOut className="w-4 h-4" />
<span>Logout</span>
</button>
</div>
)}
</div>
</div>
</header>
{/* Page Content */}
<main className="flex-1 p-4 lg:p-8 overflow-auto">
<Outlet />
</main>
</div>
{/* Mobile sidebar overlay */}
{sidebarOpen && (
<div
className="fixed inset-0 bg-black/50 z-40 lg:hidden"
onClick={() => setSidebarOpen(false)}
/>
)}
</div>
);
};
export default Layout;
|