File size: 8,502 Bytes
9580dce | 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 | "use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import {
LayoutDashboard,
BrainCircuit,
User,
MoreHorizontal,
Castle,
BookOpen,
Lightbulb,
Puzzle,
Swords,
Wand2,
Code2,
BarChart3,
Settings,
X,
MessageSquare,
} from "lucide-react";
import { useState, useEffect } from "react";
import { motion, AnimatePresence } from "framer-motion";
type TabItem = {
href: string;
label: string;
icon: React.ReactNode;
color: string;
};
// Primary tabs shown in the bottom bar (most used)
const PRIMARY_TABS: TabItem[] = [
{
href: "/",
label: "Home",
icon: <LayoutDashboard size={22} />,
color: "rgba(255,255,255,0.87)",
},
{
href: "/feynman",
label: "Feynman",
icon: <Lightbulb size={22} />,
color: "var(--color-feynman)",
},
{
href: "/coach",
label: "Coach",
icon: <BrainCircuit size={22} />,
color: "#6366f1",
},
{
href: "/profile",
label: "Profile",
icon: <User size={22} />,
color: "rgba(255,255,255,0.87)",
},
{
href: "__more__",
label: "More",
icon: <MoreHorizontal size={22} />,
color: "rgba(255,255,255,0.7)",
},
];
// All nav items for the "More" sheet
const ALL_ITEMS: TabItem[] = [
{
href: "/chess",
label: "Chess",
icon: <Castle size={20} />,
color: "var(--color-chess)",
},
{
href: "/reading",
label: "Deep Reading",
icon: <BookOpen size={20} />,
color: "var(--color-reading)",
},
{
href: "/logic",
label: "Logic Puzzles",
icon: <Puzzle size={20} />,
color: "var(--color-logic)",
},
{
href: "/critical-thinking",
label: "Critical Thinking",
icon: <Swords size={20} />,
color: "var(--color-critical-thinking)",
},
{
href: "/quests",
label: "Skill Quests",
icon: <Wand2 size={20} />,
color: "var(--color-quests)",
},
{
href: "/coding",
label: "Coding Training",
icon: <Code2 size={20} />,
color: "var(--color-coding)",
},
{
href: "/debate",
label: "Debate Arena",
icon: <MessageSquare size={20} />,
color: "var(--color-critical-thinking)",
},
{
href: "/stats",
label: "Stats",
icon: <BarChart3 size={20} />,
color: "rgba(255,255,255,0.7)",
},
{
href: "/settings",
label: "Settings",
icon: <Settings size={20} />,
color: "rgba(255,255,255,0.7)",
},
];
export function BottomTabNav() {
const pathname = usePathname();
const [moreOpen, setMoreOpen] = useState(false);
// Close sheet on route change — setState here is intentional:
// dismiss the "More" drawer whenever the user navigates to a new route.
useEffect(() => {
setMoreOpen(false); // eslint-disable-line react-hooks/set-state-in-effect
}, [pathname]);
// Prevent body scroll when sheet is open
useEffect(() => {
if (moreOpen) {
document.body.style.overflow = "hidden";
} else {
document.body.style.overflow = "";
}
return () => {
document.body.style.overflow = "";
};
}, [moreOpen]);
const isMoreActive = ALL_ITEMS.some((item) =>
pathname.startsWith(item.href)
);
return (
<>
{/* Bottom tab bar */}
<nav
className="md:hidden fixed bottom-0 left-0 right-0 z-40 flex items-stretch border-t"
style={{
background: "var(--surface-1)",
borderColor: "rgba(255,255,255,0.08)",
paddingBottom: "env(safe-area-inset-bottom)",
height: "calc(4rem + env(safe-area-inset-bottom))",
}}
aria-label="Main navigation"
>
{PRIMARY_TABS.map((tab) => {
if (tab.href === "__more__") {
const active = isMoreActive || moreOpen;
return (
<button
key="more"
onClick={() => setMoreOpen((prev) => !prev)}
className="flex-1 flex flex-col items-center justify-center gap-0.5 pt-2 pb-1 transition-colors"
style={{ color: active ? tab.color : "var(--text-muted)" }}
aria-label="More pages"
aria-expanded={moreOpen}
>
<span style={{ color: active ? tab.color : "var(--text-muted)" }}>
{moreOpen ? <X size={22} /> : tab.icon}
</span>
<span className="text-[10px] font-medium tracking-wide">
{moreOpen ? "Close" : tab.label}
</span>
</button>
);
}
const isActive =
tab.href === "/"
? pathname === "/"
: pathname.startsWith(tab.href);
return (
<Link
key={tab.href}
href={tab.href}
className="flex-1 flex flex-col items-center justify-center gap-0.5 pt-2 pb-1 transition-colors"
style={{ color: isActive ? tab.color : "var(--text-muted)" }}
aria-current={isActive ? "page" : undefined}
>
<span style={{ color: isActive ? tab.color : "var(--text-muted)" }}>
{tab.icon}
</span>
<span className="text-[10px] font-medium tracking-wide">
{tab.label}
</span>
{isActive && (
<motion.span
layoutId="bottom-tab-indicator"
className="absolute top-0 left-1/2 -translate-x-1/2 w-8 h-0.5 rounded-full"
style={{ background: tab.color }}
/>
)}
</Link>
);
})}
</nav>
{/* "More" bottom sheet — slides up from bottom */}
<AnimatePresence>
{moreOpen && (
<>
{/* Backdrop */}
<motion.div
key="backdrop"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.15 }}
className="md:hidden fixed inset-0 z-30 bg-black/60 backdrop-blur-sm"
onClick={() => setMoreOpen(false)}
aria-hidden
/>
{/* Sheet */}
<motion.div
key="sheet"
initial={{ y: "100%" }}
animate={{ y: 0 }}
exit={{ y: "100%" }}
transition={{ type: "spring", damping: 28, stiffness: 300 }}
className="md:hidden fixed bottom-0 left-0 right-0 z-40 rounded-t-2xl border-t"
style={{
background: "var(--surface-1)",
borderColor: "rgba(255,255,255,0.08)",
paddingBottom: "calc(4.5rem + env(safe-area-inset-bottom))",
}}
>
{/* Handle */}
<div className="flex justify-center pt-3 pb-1">
<div
className="w-10 h-1 rounded-full"
style={{ background: "rgba(255,255,255,0.15)" }}
/>
</div>
<div className="px-4 pt-2 pb-1">
<p
className="text-xs font-semibold uppercase tracking-widest mb-3"
style={{ color: "var(--text-muted)" }}
>
Exercises & More
</p>
<div className="grid grid-cols-2 gap-2">
{ALL_ITEMS.map((item) => {
const isActive = pathname.startsWith(item.href);
return (
<Link
key={item.href}
href={item.href}
className="flex items-center gap-3 px-3 py-3 rounded-xl text-sm font-medium transition-all"
style={{
color: isActive ? item.color : "var(--text-secondary)",
background: isActive
? `color-mix(in srgb, ${item.color} 14%, transparent)`
: "rgba(255,255,255,0.04)",
}}
>
<span style={{ color: isActive ? item.color : "var(--text-muted)" }}>
{item.icon}
</span>
<span className="truncate">{item.label}</span>
</Link>
);
})}
</div>
</div>
</motion.div>
</>
)}
</AnimatePresence>
</>
);
}
|