Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions components/mobile-nav.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"use client";

import React, { useState, useEffect } from "react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import React, { useRef, useState, useEffect, useTransition } from "react";
import { usePathname, useRouter } from "next/navigation";
import { Home, Send, Coins, Briefcase, User, Wallet } from "lucide-react";

interface NavItem {
Expand All @@ -26,8 +25,15 @@ const navItems: NavItem[] = [

export function MobileNav() {
const pathname = usePathname();
const router = useRouter();
const [isPending, startTransition] = useTransition();
const navigatingTo = useRef<string | null>(null);
const [bottomOffset, setBottomOffset] = useState(0);

useEffect(() => {
navigatingTo.current = null;
}, [pathname]);
Comment thread
Sundayabel222 marked this conversation as resolved.

useEffect(() => {
if (typeof window === "undefined" || !window.visualViewport) return;

Expand All @@ -50,6 +56,14 @@ export function MobileNav() {
};
}, []);

function handleNav(href: string) {
if (isPending || navigatingTo.current !== null || pathname === href) return;
navigatingTo.current = href;
startTransition(() => {
router.push(href);
});
}

return (
<nav
className="fixed bottom-0 left-0 right-0 border-t border-border bg-card z-40 transition-[bottom] duration-150 ease-out md:h-auto"
Expand All @@ -66,10 +80,11 @@ export function MobileNav() {
// follows the same sequence users see on screen.
const tabIndex = idx + 1;
return (
<Link
<button
key={item.href}
href={item.href}
onClick={() => handleNav(item.href)}
aria-label={item.name}
disabled={isPending}
tabIndex={tabIndex}
className={`flex flex-col items-center justify-center flex-1 h-20 gap-1 transition-colors ${
isActive
Expand All @@ -88,7 +103,7 @@ export function MobileNav() {
) : (
<span className="sr-only">{item.name}</span>
)}
</Link>
</button>
);
})}
</div>
Expand Down
Loading