diff --git a/components/mobile-nav.tsx b/components/mobile-nav.tsx index 6fbdefb..811184f 100644 --- a/components/mobile-nav.tsx +++ b/components/mobile-nav.tsx @@ -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 { @@ -26,8 +25,15 @@ const navItems: NavItem[] = [ export function MobileNav() { const pathname = usePathname(); + const router = useRouter(); + const [isPending, startTransition] = useTransition(); + const navigatingTo = useRef(null); const [bottomOffset, setBottomOffset] = useState(0); + useEffect(() => { + navigatingTo.current = null; + }, [pathname]); + useEffect(() => { if (typeof window === "undefined" || !window.visualViewport) return; @@ -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 (