-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmobile-nav.tsx
More file actions
140 lines (128 loc) · 4.76 KB
/
Copy pathmobile-nav.tsx
File metadata and controls
140 lines (128 loc) · 4.76 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
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { Menu, Plus } from "lucide-react";
import { ActivityLogDialogLazy as ActivityLogDialog } from "./activity-log-dialog-lazy";
import { navItems } from "./dashboard-nav";
import { buildMobileNavLayout } from "./mobile-nav-layout";
import { NotificationBadge } from "./notification-badge";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { cn } from "@/lib/utils";
interface MobileNavProps {
challengeId: string;
currentUserId: string;
challengeStartDate?: string;
}
export function MobileNav({ challengeId, currentUserId, challengeStartDate }: MobileNavProps) {
const pathname = usePathname();
const { leftItems, rightItems, overflowItems } = buildMobileNavLayout(navItems);
const menuActive = overflowItems.some((item) => pathname === item.href(challengeId, currentUserId));
return (
<nav
className="fixed inset-x-0 bottom-0 z-50 border-t border-white/10 bg-zinc-950 lg:hidden"
style={{ paddingBottom: "env(safe-area-inset-bottom)" }}
>
<div className="grid grid-cols-5 items-center">
{leftItems.map((item) => {
const href = item.href(challengeId, currentUserId);
const isActive = pathname === href ||
(item.label === "Home" && pathname.endsWith("/dashboard"));
return (
<Link
key={item.label}
href={href}
className={cn(
"relative flex flex-col items-center gap-1 py-3 transition-colors active:opacity-70",
isActive
? "text-white"
: "text-zinc-500 hover:text-zinc-300"
)}
>
<div className="relative">
<item.icon className="h-6 w-6" />
{item.label === "Notifications" && (
<NotificationBadge userId={currentUserId} />
)}
</div>
<span className="text-[10px] font-medium">{item.label}</span>
</Link>
);
})}
{/* Center Log Activity Button */}
<div className="flex items-center justify-center">
<ActivityLogDialog
challengeId={challengeId}
challengeStartDate={challengeStartDate}
trigger={
<button className="flex h-12 w-12 items-center justify-center rounded-full border border-white/15 bg-transparent text-zinc-100 transition hover:bg-white/10 hover:text-white active:scale-95">
<Plus className="h-6 w-6" />
</button>
}
/>
</div>
{rightItems.map((item) => {
const href = item.href(challengeId, currentUserId);
const isActive = pathname === href;
return (
<Link
key={item.label}
href={href}
className={cn(
"flex flex-col items-center gap-1 py-3 transition-colors active:opacity-70",
isActive
? "text-white"
: "text-zinc-500 hover:text-zinc-300"
)}
>
<item.icon className="h-6 w-6" />
<span className="text-[10px] font-medium">{item.label}</span>
</Link>
);
})}
<DropdownMenu>
<DropdownMenuTrigger asChild>
<button
className={cn(
"flex flex-col items-center gap-1 py-3 transition-colors w-full active:opacity-70",
menuActive ? "text-white" : "text-zinc-500 hover:text-zinc-300"
)}
aria-label="More navigation"
>
<Menu className="h-6 w-6" />
<span className="text-[10px] font-medium">More</span>
</button>
</DropdownMenuTrigger>
<DropdownMenuContent
align="end"
side="top"
className="mb-2 w-56 border-zinc-800 bg-zinc-950 text-zinc-100"
>
{overflowItems.map((item) => {
const href = item.href(challengeId, currentUserId);
const isActive = pathname === href;
return (
<DropdownMenuItem key={item.label} asChild>
<Link
href={href}
className={cn(
"flex w-full items-center gap-2",
isActive && "text-white"
)}
>
<item.icon className="h-4 w-4" />
<span>{item.label}</span>
</Link>
</DropdownMenuItem>
);
})}
</DropdownMenuContent>
</DropdownMenu>
</div>
</nav>
);
}