-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrutalistSidebar.jsx
More file actions
329 lines (308 loc) · 11.7 KB
/
BrutalistSidebar.jsx
File metadata and controls
329 lines (308 loc) · 11.7 KB
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
import React, { useRef, useState, useEffect, useCallback } from 'react';
import { NavLink, Link, useLocation, useNavigate } from 'react-router-dom';
import { motion } from 'framer-motion';
import {
CaretDoubleDownIcon,
CaretDoubleUpIcon,
ArrowRightIcon,
MagnifyingGlassIcon,
GearSixIcon,
ShuffleIcon,
EnvelopeSimpleIcon,
} from '@phosphor-icons/react';
import { version } from '../version';
import usePersistentState from '../hooks/usePersistentState';
import { KEY_SIDEBAR_STATE } from '../utils/LocalStorageManager';
import { useAchievements } from '../context/AchievementContext';
import { useSiteConfig } from '../context/SiteConfigContext';
import { appIcons as ICON_MAP } from '../utils/appIcons';
import piml from 'piml';
const BrutalistSidebar = ({
isOpen,
toggleSidebar,
toggleModal,
setIsPaletteOpen,
}) => {
const { config } = useSiteConfig();
const [sidebarConfig, setSidebarConfig] = useState(null);
useEffect(() => {
const fetchSidebarConfig = async () => {
try {
const response = await fetch('/sidebar.piml');
if (response.ok) {
const text = await response.text();
const parsed = piml.parse(text);
setSidebarConfig(parsed.sidebar);
}
} catch (error) {
console.error('Failed to load sidebar config:', error);
}
};
fetchSidebarConfig();
}, []);
const [sidebarState, setSidebarState] = usePersistentState(
KEY_SIDEBAR_STATE,
{
isMainOpen: true,
isContentOpen: true,
isSoftwareOpen: true,
isAppsOpen: true,
isStatusOpen: false,
isExtrasOpen: false,
},
);
const { unlockAchievement } = useAchievements();
const scrollRef = useRef(null);
const location = useLocation();
const navigate = useNavigate();
const [showScrollGradient, setShowScrollGradient] = useState({
top: false,
bottom: false,
});
const checkScroll = useCallback(() => {
if (scrollRef.current) {
const { scrollTop, scrollHeight, clientHeight } = scrollRef.current;
const atBottom = Math.ceil(scrollTop + clientHeight) >= scrollHeight;
const atTop = scrollTop <= 0;
const isScrollable = scrollHeight > clientHeight;
setShowScrollGradient({
top: isScrollable && !atTop,
bottom: isScrollable && !atBottom,
});
}
}, []);
useEffect(() => {
checkScroll();
const scrollElement = scrollRef.current;
if (scrollElement) {
scrollElement.addEventListener('scroll', checkScroll);
window.addEventListener('resize', checkScroll);
}
return () => {
if (scrollElement) {
scrollElement.removeEventListener('scroll', checkScroll);
window.removeEventListener('resize', checkScroll);
}
};
}, [isOpen, sidebarState, checkScroll]);
const toggleSection = (section) => {
setSidebarState((prevState) => ({
...prevState,
[section]: !prevState[section],
}));
};
const getLinkClass = ({ isActive }) =>
`group flex items-center justify-between px-6 py-3 transition-all duration-300 border-b border-white/5 ${
isActive
? 'bg-emerald-500/10 text-white'
: 'text-gray-300 hover:text-white hover:bg-white/5'
}`;
const SectionHeader = ({ id, label, isOpen, active }) => (
<button
onClick={() => toggleSection(id)}
className={`flex items-center justify-between w-full px-6 py-4 border-b border-white/10 transition-all duration-300 ${
active
? 'bg-emerald-500/5 text-emerald-400 border-l-2 border-emerald-500'
: 'text-gray-600 hover:text-gray-400 border-l-2 border-transparent'
}`}
>
<span className="font-arvo text-[11px] uppercase tracking-[0.2em]">
{'//'} {label}
</span>
<span
className={`transform transition-transform duration-300 ${isOpen ? 'rotate-180' : ''}`}
>
↓
</span>
</button>
);
const sidebarVariants = {
open: { x: 0, transition: { type: 'circOut', duration: 0.4 } },
closed: { x: '-100%', transition: { type: 'circIn', duration: 0.3 } },
};
return (
<>
<div
className={`fixed inset-0 bg-black/80 backdrop-blur-sm z-40 md:hidden transition-opacity ${
isOpen
? 'opacity-100 pointer-events-auto'
: 'opacity-0 pointer-events-none'
}`}
onClick={toggleSidebar}
/>
<motion.aside
initial={false}
animate={isOpen ? 'open' : 'closed'}
variants={sidebarVariants}
className="fixed top-0 left-0 h-screen w-72 bg-[#060608] z-50 flex flex-col border-r border-white/10 shadow-2xl"
>
<div className="p-8 border-b border-white/10 flex flex-col gap-2 bg-black/50 relative">
<div className="absolute top-0 left-0 w-full h-[2px] bg-gradient-to-r from-emerald-500/60 via-amber-500/30 to-transparent" />
<Link
to="/"
className="flex items-center gap-3 group"
onClick={
isOpen && window.innerWidth < 768 ? toggleSidebar : undefined
}
>
<span className="text-xl font-black uppercase tracking-tighter text-white">
{config?.hero?.title?.toLowerCase().endsWith('codex') ? (
<>
{config.hero.title.slice(0, -5)}
<span className="text-emerald-500">codex</span>
</>
) : (
config?.hero?.title || 'Fezcodex'
)}
</span>
</Link>
<span className="font-arvo text-[10px] text-gray-500 uppercase tracking-widest font-medium">
Digital Archive Kernel {'//'} v{version} {'//'}{' '}
{config?.kernel?.codename}
</span>
</div>
{/* Scrollable Content */}
<div className="relative flex-grow overflow-hidden">
{showScrollGradient.top && (
<div className="absolute top-0 left-0 right-0 h-12 flex items-center justify-center bg-gradient-to-b from-[#050505] to-transparent z-20 pointer-events-none">
<CaretDoubleUpIcon size={16} className="text-emerald-500 mt-2" />
</div>
)}
<div
ref={scrollRef}
className="h-full overflow-y-auto scrollbar-hide no-scrollbar"
>
{Array.isArray(sidebarConfig) &&
sidebarConfig.map((section, sectionIdx) => {
const items = Array.isArray(section.content)
? section.content
: [];
const isActive = items.some((item) =>
item.to === '/'
? location.pathname === '/'
: item.to && location.pathname.startsWith(item.to),
);
return (
<React.Fragment key={section.id || sectionIdx}>
<SectionHeader
id={section.id}
label={section.label}
isOpen={sidebarState[section.id]}
active={isActive}
/>
{sidebarState[section.id] && (
<nav className="flex flex-col">
{items.map((item, idx) => {
const Icon = ICON_MAP[item.icon] || ArrowRightIcon;
if (item.external === 'true' || item.url || (item.to && item.to.startsWith('http'))) {
/*
Use native <a> tag for external absolute URLs to bypass React Router.
This allows the browser to perform a normal page navigation instead of
React Router attempting to resolve it internally which causes a 404.
*/
return (
<a
key={idx}
href={item.url || item.to}
className="group flex items-center justify-between px-6 py-3 transition-all duration-300 border-b border-white/5 text-gray-300 hover:text-white hover:bg-white/5"
>
<div className="flex items-center gap-4">
<Icon size={18} weight="bold" />
<span className="font-arvo text-sm font-medium uppercase tracking-widest">
{item.label}
</span>
</div>
<ArrowRightIcon
size={14}
className="opacity-0 group-hover:opacity-100 -translate-x-2 group-hover:translate-x-0 transition-all"
/>
</a>
);
}
return (
<SidebarLink
key={idx}
to={item.to}
icon={Icon}
label={item.label}
getLinkClass={getLinkClass}
/>
);
})}
</nav>
)}
</React.Fragment>
);
})}
</div>
{showScrollGradient.bottom && (
<div className="absolute bottom-0 left-0 right-0 h-12 flex items-center justify-center bg-gradient-to-t from-[#050505] to-transparent z-20 pointer-events-none">
<CaretDoubleDownIcon
size={16}
className="text-emerald-500 mb-2"
/>
</div>
)}
</div>
<div className="p-4 border-t border-white/10 bg-black/50">
<div className="grid grid-cols-4 gap-2 mb-4">
<FooterButton
onClick={() => setIsPaletteOpen(true)}
icon={MagnifyingGlassIcon}
title="COMMANDS"
/>
<FooterButton
onClick={() => navigate('/settings')}
icon={GearSixIcon}
title="SETTINGS"
/>
<FooterButton
onClick={() => {
navigate('/random');
unlockAchievement('feeling_lucky');
}}
icon={ShuffleIcon}
title="RANDOM"
/>
<FooterButton
onClick={toggleModal}
icon={EnvelopeSimpleIcon}
title="CONTACT"
/>
</div>
<div className="text-center">
<p className="font-arvo text-[10px] text-gray-600 uppercase tracking-widest font-medium">
{`© ${new Date().getFullYear()} Fezcode // Theme: Brutalist`}
</p>
</div>
</div>
</motion.aside>
</>
);
};
const SidebarLink = ({ to, icon: Icon, label, getLinkClass }) => (
<NavLink to={to} className={getLinkClass}>
<div className="flex items-center gap-4">
<Icon size={18} weight="bold" />
<span className="font-arvo text-sm font-medium uppercase tracking-widest">
{label}
</span>
</div>
<ArrowRightIcon
size={14}
className="opacity-0 group-hover:opacity-100 -translate-x-2 group-hover:translate-x-0 transition-all"
/>
</NavLink>
);
const FooterButton = ({ onClick, icon: Icon, title }) => (
<button
onClick={onClick}
title={title}
className="group flex flex-col items-center justify-center p-2 border border-white/[0.08] bg-white/[0.03] hover:bg-emerald-400 hover:border-emerald-400 transition-all aspect-square"
>
<div className="text-white group-hover:text-black transition-all">
<Icon size={18} weight="bold" />
</div>
</button>
);
export default BrutalistSidebar;