// islands/NavigationBar.tsx import { useComputed, useSignal } from "@preact/signals"; import { useEffect } from "preact/hooks"; import { LuCodeXml, LuHouse, LuNotebookPen } from "@preact-icons/lu"; interface NavigationBarProps { currentPath: string; } export default function NavigationBar({ currentPath }: NavigationBarProps) { const isScrolling = useSignal(false); const prevScrollPos = useSignal(0); const isVisible = useComputed(() => { if (prevScrollPos.value < 50) return true; const currentPos = typeof window !== "undefined" ? globalThis.scrollY : 0; return prevScrollPos.value > currentPos; }); const isPostsPath = (path: string) => { return path.startsWith("/posts") || path.startsWith("/post/"); }; useEffect(() => { let scrollTimer: number | undefined; const handleScroll = () => { isScrolling.value = true; prevScrollPos.value = globalThis.scrollY; if (scrollTimer) clearTimeout(scrollTimer); scrollTimer = setTimeout(() => { isScrolling.value = false; }, 200); }; globalThis.addEventListener("scroll", handleScroll); return () => { globalThis.removeEventListener("scroll", handleScroll); if (scrollTimer) clearTimeout(scrollTimer); }; }, []); return (
); }