-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathNavBarMantine.tsx
More file actions
609 lines (582 loc) · 19.7 KB
/
NavBarMantine.tsx
File metadata and controls
609 lines (582 loc) · 19.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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
'use client';
import { useState, useEffect } from 'react';
import Link from 'next/link';
import {
Group,
Button,
Text,
Box,
Burger,
Drawer,
Stack,
ActionIcon,
useMantineColorScheme,
Menu,
Avatar,
UnstyledButton,
Container,
Kbd,
Divider,
ThemeIcon,
} from '@mantine/core';
import { useDisclosure } from '@mantine/hooks';
import { spotlight } from '@mantine/spotlight';
import {
IconSun,
IconMoon,
IconDeviceDesktop,
IconBrandGithub,
IconChevronDown,
IconLogout,
IconFileText,
IconSearch,
IconBook,
IconClock,
IconCalendar,
IconInfoCircle,
IconUser,
IconCheck,
IconExternalLink,
IconBug,
IconSparkles,
IconTable,
IconFlag,
} from '@tabler/icons-react';
import { useAuth } from '@/context/AuthContext';
import { useMenu } from '@/context/MenuContext';
import { GT_COLORS } from '@/lib/theme';
const navLinks = [
{ label: 'Recents', href: '/recents', icon: IconClock },
{ label: 'Schedule', href: '/schedule', icon: IconCalendar },
{ label: 'About', href: '/about', icon: IconInfoCircle },
];
export function NavBarMantine() {
const [drawerOpened, { toggle: toggleDrawer, close: closeDrawer }] = useDisclosure(false);
const [mounted, setMounted] = useState(false);
const { colorScheme, setColorScheme } = useMantineColorScheme();
// Get the current theme icon based on color scheme
const getThemeIcon = () => {
if (!mounted) return <IconSun size={18} />;
if (colorScheme === 'auto') return <IconDeviceDesktop size={18} />;
if (colorScheme === 'dark') return <IconMoon size={18} />;
return <IconSun size={18} />;
};
// Prevent hydration mismatch by only rendering theme-dependent UI after mount
useEffect(() => {
setMounted(true);
}, []);
const authContext = useAuth();
const user = authContext?.user;
const loading = authContext?.loading;
const logout = authContext?.logout;
// Helper to get user display values from Supabase user metadata
const displayName = user?.user_metadata?.full_name || user?.email?.split('@')[0] || 'User';
const photoURL = user?.user_metadata?.avatar_url || null;
const { handleLoginOpen } = useMenu();
return (
<Box
component="header"
style={{
backgroundColor: GT_COLORS.navy,
borderBottom: `1px solid ${GT_COLORS.techGold}20`,
position: 'sticky',
top: 0,
zIndex: 100,
}}
>
<Container size="xl">
<Group h={64} justify="space-between">
{/* Logo and Nav Links */}
<Group gap="xl">
<Link href="/" style={{ textDecoration: 'none' }}>
<Group gap="xs">
<ThemeIcon
size={36}
radius="md"
variant="gradient"
gradient={{ from: GT_COLORS.techGold, to: GT_COLORS.buzzGold }}
>
<IconBook size={20} color={GT_COLORS.navy} />
</ThemeIcon>
<Text size="xl" fw={700} c="white">
<Text component="span" style={{ color: GT_COLORS.techGold }} inherit>OMS</Text>Hub
</Text>
</Group>
</Link>
{/* Desktop Navigation */}
<Group gap={4} visibleFrom="md">
{navLinks.map((link) => (
<Button
key={link.href}
component={Link}
href={link.href}
variant="subtle"
size="sm"
fw={500}
leftSection={<link.icon size={16} />}
styles={{
root: {
color: 'rgba(255,255,255,0.85)',
'&:hover': {
backgroundColor: 'rgba(255,255,255,0.1)',
color: 'white',
},
},
}}
>
{link.label}
</Button>
))}
</Group>
</Group>
{/* Right Side Actions */}
<Group gap="sm" visibleFrom="sm">
{/* Search Button */}
<Button
variant="default"
leftSection={<IconSearch size={14} />}
rightSection={
<Group gap={4}>
<Kbd size="xs" style={{ backgroundColor: 'rgba(255,255,255,0.15)', color: 'white', border: 'none' }}>⌘</Kbd>
<Kbd size="xs" style={{ backgroundColor: 'rgba(255,255,255,0.15)', color: 'white', border: 'none' }}>K</Kbd>
</Group>
}
onClick={() => spotlight.open()}
styles={{
root: {
backgroundColor: 'rgba(255,255,255,0.08)',
borderColor: 'rgba(255,255,255,0.15)',
color: 'rgba(255,255,255,0.7)',
'&:hover': {
backgroundColor: 'rgba(255,255,255,0.12)',
borderColor: 'rgba(255,255,255,0.25)',
},
},
}}
>
Search courses...
</Button>
<Divider orientation="vertical" color="rgba(255,255,255,0.15)" h={24} style={{ alignSelf: 'center' }} />
<Menu shadow="md" width={220} position="bottom-end" radius="md">
<Menu.Target>
<ActionIcon
variant="subtle"
title="GitHub"
styles={{
root: {
color: 'rgba(255,255,255,0.7)',
'&:hover': {
backgroundColor: 'rgba(255,255,255,0.1)',
color: 'white',
},
},
}}
>
<IconBrandGithub size={18} />
</ActionIcon>
</Menu.Target>
<Menu.Dropdown>
<Menu.Label>GitHub</Menu.Label>
<Menu.Item
leftSection={<IconExternalLink size={16} />}
component="a"
href="https://github.com/omshub/website/"
target="_blank"
rel="noopener noreferrer"
>
View Repository
</Menu.Item>
<Menu.Divider />
<Menu.Label>Open an Issue</Menu.Label>
<Menu.Item
leftSection={<IconBug size={16} />}
component="a"
href="https://github.com/omshub/website/issues/new?template=bug_report.yml"
target="_blank"
rel="noopener noreferrer"
>
Report a Bug
</Menu.Item>
<Menu.Item
leftSection={<IconSparkles size={16} />}
component="a"
href="https://github.com/omshub/website/issues/new?template=feature_request.yml"
target="_blank"
rel="noopener noreferrer"
>
Request a Feature
</Menu.Item>
<Menu.Item
leftSection={<IconTable size={16} />}
component="a"
href="https://github.com/omshub/website/issues/new?template=course_data.yml"
target="_blank"
rel="noopener noreferrer"
>
Report Course Data Issue
</Menu.Item>
<Menu.Item
leftSection={<IconFlag size={16} />}
component="a"
href="https://github.com/omshub/website/issues/new?template=flag_review.yml"
target="_blank"
rel="noopener noreferrer"
>
Flag Inappropriate Review
</Menu.Item>
</Menu.Dropdown>
</Menu>
<Menu shadow="md" width={160} position="bottom-end" radius="md">
<Menu.Target>
<ActionIcon
variant="subtle"
title="Change theme"
styles={{
root: {
color: 'rgba(255,255,255,0.7)',
'&:hover': {
backgroundColor: 'rgba(255,255,255,0.1)',
color: 'white',
},
},
}}
>
{getThemeIcon()}
</ActionIcon>
</Menu.Target>
<Menu.Dropdown>
<Menu.Label>Theme</Menu.Label>
<Menu.Item
leftSection={<IconDeviceDesktop size={16} />}
rightSection={colorScheme === 'auto' && mounted ? <IconCheck size={14} /> : null}
onClick={() => setColorScheme('auto')}
>
System
</Menu.Item>
<Menu.Item
leftSection={<IconSun size={16} />}
rightSection={colorScheme === 'light' && mounted ? <IconCheck size={14} /> : null}
onClick={() => setColorScheme('light')}
>
Light
</Menu.Item>
<Menu.Item
leftSection={<IconMoon size={16} />}
rightSection={colorScheme === 'dark' && mounted ? <IconCheck size={14} /> : null}
onClick={() => setColorScheme('dark')}
>
Dark
</Menu.Item>
</Menu.Dropdown>
</Menu>
{!loading && (
<>
{!user ? (
<Button
variant="filled"
size="sm"
onClick={handleLoginOpen}
leftSection={<IconUser size={16} />}
styles={{
root: {
backgroundColor: GT_COLORS.techGold,
color: GT_COLORS.navy,
'&:hover': {
backgroundColor: GT_COLORS.buzzGold,
},
},
}}
>
Sign In
</Button>
) : (
<Menu shadow="lg" width={220} position="bottom-end" radius="md">
<Menu.Target>
<UnstyledButton>
<Group gap="xs">
<Avatar
src={photoURL}
alt={displayName}
radius="xl"
size={36}
style={{ border: `2px solid ${GT_COLORS.techGold}` }}
imageProps={{ referrerPolicy: 'no-referrer' }}
/>
<IconChevronDown size={14} color="rgba(255,255,255,0.7)" />
</Group>
</UnstyledButton>
</Menu.Target>
<Menu.Dropdown>
<Menu.Label>
<Text size="sm" fw={600} truncate>
{displayName}
</Text>
<Text size="xs" c="dimmed" truncate>
{user?.email}
</Text>
</Menu.Label>
<Menu.Divider />
<Menu.Item
leftSection={<IconFileText size={16} />}
component={Link}
href="/user/reviews"
>
My Reviews
</Menu.Item>
<Menu.Divider />
<Menu.Item
color="red"
leftSection={<IconLogout size={16} />}
onClick={() => logout?.()}
>
Sign Out
</Menu.Item>
</Menu.Dropdown>
</Menu>
)}
</>
)}
</Group>
{/* Mobile Menu Button */}
<Burger
opened={drawerOpened}
onClick={toggleDrawer}
hiddenFrom="sm"
color="white"
size="sm"
aria-label={drawerOpened ? 'Close navigation menu' : 'Open navigation menu'}
/>
</Group>
</Container>
{/* Mobile Drawer */}
<Drawer
opened={drawerOpened}
onClose={closeDrawer}
size="100%"
padding="lg"
title={
<Group gap="xs">
<ThemeIcon
size={32}
radius="md"
variant="gradient"
gradient={{ from: GT_COLORS.techGold, to: GT_COLORS.buzzGold }}
>
<IconBook size={18} color={GT_COLORS.navy} />
</ThemeIcon>
<Text size="xl" fw={700}>
<Text component="span" style={{ color: GT_COLORS.techGold }} inherit>OMS</Text>Hub
</Text>
</Group>
}
hiddenFrom="sm"
zIndex={1000}
styles={{
header: {
borderBottom: `1px solid var(--mantine-color-gray-2)`,
},
}}
>
<Stack gap="xs">
{/* Search */}
<Button
variant="subtle"
color="gray"
leftSection={<IconSearch size={18} />}
onClick={() => { spotlight.open(); closeDrawer(); }}
fullWidth
size="md"
justify="flex-start"
>
Search courses...
</Button>
<Divider />
{/* Navigation Links */}
{navLinks.map((link) => (
<Button
key={link.href}
component={Link}
href={link.href}
variant="subtle"
color="gray"
fullWidth
justify="flex-start"
size="md"
leftSection={<link.icon size={18} />}
onClick={closeDrawer}
>
{link.label}
</Button>
))}
<Divider />
{/* Actions */}
<Stack gap="xs">
<Text size="sm" fw={500} c="dimmed">Theme</Text>
<Group gap="xs">
<ActionIcon
variant={colorScheme === 'auto' && mounted ? 'filled' : 'light'}
color={colorScheme === 'auto' && mounted ? 'blue' : 'gray'}
onClick={() => setColorScheme('auto')}
size="lg"
title="System theme"
>
<IconDeviceDesktop size={18} />
</ActionIcon>
<ActionIcon
variant={colorScheme === 'light' && mounted ? 'filled' : 'light'}
color={colorScheme === 'light' && mounted ? 'blue' : 'gray'}
onClick={() => setColorScheme('light')}
size="lg"
title="Light theme"
>
<IconSun size={18} />
</ActionIcon>
<ActionIcon
variant={colorScheme === 'dark' && mounted ? 'filled' : 'light'}
color={colorScheme === 'dark' && mounted ? 'blue' : 'gray'}
onClick={() => setColorScheme('dark')}
size="lg"
title="Dark theme"
>
<IconMoon size={18} />
</ActionIcon>
</Group>
</Stack>
<Divider />
{/* GitHub */}
<Stack gap="xs">
<Text size="sm" fw={500} c="dimmed">GitHub</Text>
<Button
variant="subtle"
color="gray"
component="a"
href="https://github.com/omshub/website/"
target="_blank"
rel="noopener noreferrer"
fullWidth
justify="flex-start"
size="md"
leftSection={<IconExternalLink size={18} />}
>
View Repository
</Button>
<Button
variant="subtle"
color="gray"
component="a"
href="https://github.com/omshub/website/issues/new?template=bug_report.yml"
target="_blank"
rel="noopener noreferrer"
fullWidth
justify="flex-start"
size="md"
leftSection={<IconBug size={18} />}
>
Report a Bug
</Button>
<Button
variant="subtle"
color="gray"
component="a"
href="https://github.com/omshub/website/issues/new?template=feature_request.yml"
target="_blank"
rel="noopener noreferrer"
fullWidth
justify="flex-start"
size="md"
leftSection={<IconSparkles size={18} />}
>
Request a Feature
</Button>
<Button
variant="subtle"
color="gray"
component="a"
href="https://github.com/omshub/website/issues/new?template=course_data.yml"
target="_blank"
rel="noopener noreferrer"
fullWidth
justify="flex-start"
size="md"
leftSection={<IconTable size={18} />}
>
Report Course Data Issue
</Button>
<Button
variant="subtle"
color="gray"
component="a"
href="https://github.com/omshub/website/issues/new?template=flag_review.yml"
target="_blank"
rel="noopener noreferrer"
fullWidth
justify="flex-start"
size="md"
leftSection={<IconFlag size={18} />}
>
Flag Inappropriate Review
</Button>
</Stack>
<Divider />
{/* Auth */}
{!loading && !user && (
<Button
variant="filled"
size="md"
onClick={() => { handleLoginOpen(); closeDrawer(); }}
leftSection={<IconUser size={18} />}
style={{
backgroundColor: GT_COLORS.techGold,
color: GT_COLORS.navy,
}}
>
Sign In
</Button>
)}
{!loading && user && (
<Stack gap="xs">
<Group gap="sm" p="xs" style={{ backgroundColor: 'var(--mantine-color-default)', borderRadius: 8 }}>
<Avatar
src={photoURL}
alt={displayName}
radius="xl"
size="md"
imageProps={{ referrerPolicy: 'no-referrer' }}
/>
<div style={{ flex: 1, minWidth: 0 }}>
<Text size="sm" fw={600} truncate>
{displayName}
</Text>
<Text size="xs" c="dimmed" truncate>
{user?.email}
</Text>
</div>
</Group>
<Button
component={Link}
href="/user/reviews"
variant="light"
leftSection={<IconFileText size={18} />}
fullWidth
justify="flex-start"
onClick={closeDrawer}
>
My Reviews
</Button>
<Button
variant="light"
color="red"
leftSection={<IconLogout size={18} />}
fullWidth
justify="flex-start"
onClick={() => { logout?.(); closeDrawer(); }}
>
Sign Out
</Button>
</Stack>
)}
</Stack>
</Drawer>
</Box>
);
}