diff --git a/src/components/mobile-nav.tsx b/src/components/mobile-nav.tsx index 5ff9b6d..7486423 100644 --- a/src/components/mobile-nav.tsx +++ b/src/components/mobile-nav.tsx @@ -2,42 +2,53 @@ import { Button } from "@/components/ui/button" import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/sheet" +import { useColorSections } from "@/hooks/color-sections" import type { Sections, translations } from "@/i18n/translations" -import { cn } from "@/lib/utils" import { Menu } from "lucide-react" +import { useRef } from "react" import { LanguageSelector } from "./ui/language-selector" +function NavContent({ + t, + linksOrder +}: { + t: typeof translations.pl, + linksOrder: Array +}) { + const parent = useRef(null); + useColorSections(parent); + return ( + + ) +} + export function MobileNav({ t, linksOrder, - activeSection }: { t: typeof translations.pl linksOrder: Array - activeSection: Sections }) { return ( - + - + {t.mobileNav.menu} - + ) diff --git a/src/components/nav.tsx b/src/components/nav.tsx index f549469..a368f5a 100644 --- a/src/components/nav.tsx +++ b/src/components/nav.tsx @@ -1,9 +1,10 @@ "use client" import { Button } from "@/components/ui/button" -import { Sections, type translations } from "@/i18n/translations" +import { useColorSections } from "@/hooks/color-sections" +import { type translations } from "@/i18n/translations" import { cn } from "@/lib/utils" import { MoonIcon, SunIcon } from "lucide-react" -import { useEffect, useState } from "react" +import { useRef } from "react" import { MobileNav } from "./mobile-nav" import { useTheme } from "./providers" import { LanguageSelector } from "./ui/language-selector" @@ -25,50 +26,8 @@ export function Nav({ t: typeof translations.pl }) { const { theme, setTheme } = useTheme() - const [activeSection, setActiveSection] = useState("about") - - - useEffect(() => { - const options = { - root: null, - rootMargin: "-10px", - threshold: 0.5, // Adjust the visibility threshold as needed - }; - let timeout: NodeJS.Timeout | null = null; - - - const observer = new IntersectionObserver((entries) => { - if (timeout) { - clearTimeout(timeout); - } - entries.forEach(entry => { - const target = entry.target.id as keyof (typeof translations.pl)["nav"] - if (entry.isIntersecting) { - setActiveSection(target); - if (window.location.hash !== `#${target}` && history.replaceState) { - timeout = setTimeout(() => { - history.replaceState(null, "", `#${target}`) - }, 150) - } - } - }); - }, options); - - const sections = linksOrder.map(value => document.getElementById(value)); - sections.forEach(section => { - if (section) { - observer.observe(section); - } - }); - - return () => { - sections.forEach(section => { - if (section) { - observer.unobserve(section); - } - }); - }; - }, []); + const parent = useRef(null); + useColorSections(parent); return (