Spaces:
Sleeping
Sleeping
File size: 9,278 Bytes
759768a |
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 262 263 |
import React, { useState } from 'react';
import { authManager } from '../utils/auth';
const Header = ({ currentUser, onNavigate, onAuthChange }) => {
const [showUserMenu, setShowUserMenu] = useState(false);
const [isLoggingOut, setIsLoggingOut] = useState(false);
const handleLogout = async () => {
setIsLoggingOut(true);
try {
await authManager.logout();
const guestUser = authManager.getCurrentUser();
onAuthChange && onAuthChange(guestUser);
setShowUserMenu(false);
onNavigate && onNavigate('Dashboard');
} catch (error) {
console.error('Logout failed:', error);
} finally {
setIsLoggingOut(false);
}
};
return (
<header style={{
background: 'linear-gradient(135deg, #2c3e50 0%, #34495e 100%)',
color: 'white',
padding: '15px 20px',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
boxShadow: '0 2px 10px rgba(0,0,0,0.1)',
position: 'sticky',
top: 0,
zIndex: 1000
}}>
{/* Logo */}
<div
onClick={() => onNavigate && onNavigate('Dashboard')}
style={{
display: 'flex',
alignItems: 'center',
gap: '10px',
cursor: 'pointer',
fontSize: '1.5rem',
fontWeight: 'bold'
}}
>
<span style={{ fontSize: '2rem' }}>πΏ</span>
GreenPlus by GXS
</div>
{/* User Section */}
<div style={{ position: 'relative' }}>
{currentUser ? (
<div style={{ display: 'flex', alignItems: 'center', gap: '15px' }}>
{/* User Stats */}
<div style={{
display: 'flex',
alignItems: 'center',
gap: '15px',
fontSize: '0.9rem',
opacity: 0.9
}}>
<span>β Level {authManager.getUserStats().level}</span>
<span>π {authManager.getUserStats().points} pts</span>
</div>
{/* User Menu */}
<div
onClick={() => setShowUserMenu(!showUserMenu)}
style={{
display: 'flex',
alignItems: 'center',
gap: '8px',
cursor: 'pointer',
padding: '8px 12px',
borderRadius: '20px',
background: 'rgba(255,255,255,0.1)',
transition: 'background 0.2s'
}}
>
<span style={{ fontSize: '1.2rem' }}>{currentUser.avatar}</span>
<span style={{ fontWeight: '500' }}>{currentUser.name}</span>
<span style={{ fontSize: '0.8rem' }}>βΌ</span>
</div>
{/* Dropdown Menu */}
{showUserMenu && (
<div style={{
position: 'absolute',
top: '100%',
right: 0,
marginTop: '10px',
background: 'white',
borderRadius: '12px',
boxShadow: '0 4px 20px rgba(0,0,0,0.15)',
minWidth: '200px',
overflow: 'hidden',
zIndex: 1001
}}>
<div style={{
padding: '15px',
borderBottom: '1px solid #ecf0f1',
background: '#f8f9fa'
}}>
<div style={{ fontWeight: 'bold', color: '#2c3e50' }}>
{currentUser.name}
</div>
<div style={{ fontSize: '0.9rem', color: '#7f8c8d' }}>
{currentUser.email}
</div>
{currentUser.isGuest && (
<div style={{
fontSize: '0.8rem',
color: '#e67e22',
marginTop: '5px',
fontWeight: '500'
}}>
π Guest Mode
</div>
)}
</div>
<div style={{ padding: '10px 0' }}>
<button
onClick={() => {
setShowUserMenu(false);
onNavigate && onNavigate('Profile');
}}
style={{
width: '100%',
padding: '12px 20px',
background: 'none',
border: 'none',
textAlign: 'left',
cursor: 'pointer',
color: '#2c3e50',
display: 'flex',
alignItems: 'center',
gap: '10px',
fontSize: '14px'
}}
onMouseEnter={(e) => e.target.style.background = '#f8f9fa'}
onMouseLeave={(e) => e.target.style.background = 'none'}
>
π€ View Profile
</button>
<button
onClick={() => {
setShowUserMenu(false);
onNavigate && onNavigate('Community');
}}
style={{
width: '100%',
padding: '12px 20px',
background: 'none',
border: 'none',
textAlign: 'left',
cursor: 'pointer',
color: '#2c3e50',
display: 'flex',
alignItems: 'center',
gap: '10px',
fontSize: '14px'
}}
onMouseEnter={(e) => e.target.style.background = '#f8f9fa'}
onMouseLeave={(e) => e.target.style.background = 'none'}
>
π₯ Community
</button>
{currentUser.isGuest ? (
<button
onClick={() => {
setShowUserMenu(false);
onNavigate && onNavigate('Login');
}}
style={{
width: '100%',
padding: '12px 20px',
background: 'none',
border: 'none',
textAlign: 'left',
cursor: 'pointer',
color: '#27ae60',
display: 'flex',
alignItems: 'center',
gap: '10px',
fontSize: '14px',
fontWeight: '500'
}}
onMouseEnter={(e) => e.target.style.background = '#f8f9fa'}
onMouseLeave={(e) => e.target.style.background = 'none'}
>
π Create Account
</button>
) : (
<button
onClick={handleLogout}
disabled={isLoggingOut}
style={{
width: '100%',
padding: '12px 20px',
background: 'none',
border: 'none',
textAlign: 'left',
cursor: isLoggingOut ? 'not-allowed' : 'pointer',
color: '#e74c3c',
display: 'flex',
alignItems: 'center',
gap: '10px',
fontSize: '14px',
opacity: isLoggingOut ? 0.6 : 1
}}
onMouseEnter={(e) => !isLoggingOut && (e.target.style.background = '#f8f9fa')}
onMouseLeave={(e) => e.target.style.background = 'none'}
>
{isLoggingOut ? 'β³ Logging out...' : 'πͺ Logout'}
</button>
)}
</div>
</div>
)}
</div>
) : (
<button
onClick={() => onNavigate && onNavigate('Login')}
style={{
padding: '10px 20px',
background: 'linear-gradient(135deg, #27ae60 0%, #2ecc71 100%)',
color: 'white',
border: 'none',
borderRadius: '20px',
cursor: 'pointer',
fontWeight: '500',
fontSize: '14px'
}}
>
π Sign In
</button>
)}
</div>
{/* Click outside to close menu */}
{showUserMenu && (
<div
onClick={() => setShowUserMenu(false)}
style={{
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
zIndex: 999
}}
/>
)}
</header>
);
};
export default Header; |