From 975fd2f52b226ee3033f163bcc8025cf8d253372 Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk Date: Thu, 13 Feb 2025 01:34:53 +0100 Subject: [PATCH] test5 --- src/components/nav.tsx | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/components/nav.tsx b/src/components/nav.tsx index fa3698c..8568aa6 100644 --- a/src/components/nav.tsx +++ b/src/components/nav.tsx @@ -3,7 +3,7 @@ import { Button } from "@/components/ui/button" import { Sections, type translations } from "@/i18n/translations" import { cn } from "@/lib/utils" import { MoonIcon, SunIcon } from "lucide-react" -import { useDeferredValue, useEffect, useState } from "react" +import { useEffect, useState } from "react" import { MobileNav } from "./mobile-nav" import { useTheme } from "./providers" import { LanguageSelector } from "./ui/language-selector" @@ -25,8 +25,8 @@ export function Nav({ t: typeof translations.pl }) { const { theme, setTheme } = useTheme() - const [activeSection, setActiveSection] = useState("about") - const deferedActiveSection = useDeferredValue(activeSection) + const [activeSection,] = useState("about") + // const deferedActiveSection = useDeferredValue(activeSection) useEffect(() => { @@ -35,24 +35,25 @@ export function Nav({ rootMargin: "-10px", threshold: 0.5, // Adjust the visibility threshold as needed }; - let timeout: NodeJS.Timeout | null = null; + // let timeout: NodeJS.Timeout | null = null; const observer = new IntersectionObserver((entries) => { - if (timeout) { - clearTimeout(timeout); + // if (timeout) { + // clearTimeout(timeout); + // } + for (const entry of entries) { + // const target = entry.target.id as keyof (typeof translations.pl)["nav"] + // if (activeSection !== target && entry.intersectionRatio > 0) { + // // setActiveSection(target); + // if (window.location.hash !== `#${target}` && history.replaceState) { + // timeout = setTimeout(() => { + // history.replaceState(null, "", `#${target}`) + // }, 150) + // } + // } + // break; } - entries.forEach(entry => { - const target = entry.target.id as keyof (typeof translations.pl)["nav"] - if (entry.intersectionRatio > 0) { - 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)); @@ -86,12 +87,12 @@ export function Nav({ key={value} href={`#${value}`} className={cn("text-sm md:text-md hover:text-primary transition-colors relative group will-change-[color]", { - 'text-primary': deferedActiveSection === value + 'text-primary': activeSection === value })} > {t.nav[value]} ))} @@ -110,7 +111,7 @@ export function Nav({ {/* Mobile Navigation */}
- +