"use client"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { Home, Search, Sparkles, Plus, Menu as MenuIcon, X } from "lucide-react"; import { useUI } from "@/lib/client/store"; import { cn } from "@/lib/utils"; import { api } from "@/lib/client/api"; import { Sidebar } from "./Sidebar"; import { useQuery } from "@tanstack/react-query"; import type { TreeNode } from "./types"; export function MobileNav() { const pathname = usePathname(); const ui = useUI(); const r = useRouter(); const [drawer, setDrawer] = useState(false); const { data: tree = [] } = useQuery({ queryKey: ["tree"], queryFn: () => api("/api/tree") }); useEffect(() => { let sx = 0, sy = 0, edge = false; const ts = (e: TouchEvent) => { const t = e.touches[0]; sx = t.clientX; sy = t.clientY; edge = sx < 24; }; const te = (e: TouchEvent) => { if (!edge) return; const t = e.changedTouches[0]; if (t.clientX - sx > 70 && Math.abs(t.clientY - sy) < 60) setDrawer(true); }; window.addEventListener("touchstart", ts, { passive: true }); window.addEventListener("touchend", te, { passive: true }); return () => { window.removeEventListener("touchstart", ts); window.removeEventListener("touchend", te); }; }, []); if (ui.focusMode) return null; const I = ({ active, onClick, href, icon, label }: { active?: boolean; onClick?: () => void; href?: string; icon: React.ReactNode; label: string }) => { const cls = cn("flex flex-1 flex-col items-center justify-center gap-0.5 py-1.5 text-[10px] text-fg-muted [&_svg]:size-5", active && "text-accent"); return href ? {icon}{label} : ; }; return ( <> {drawer && (
setDrawer(false)}>
e.stopPropagation()}> setDrawer(false)} />
)} ); }