'use client' import Link from 'next/link' import { useEffect, useState } from 'react' import { cn } from '@/lib/utils' import { useScrollContext } from '@/app/providers/LenisProvider' type Item = { href: string; label: string } const items: Item[] = [ { href: '#about', label: 'About' }, { href: '#writing', label: 'Writing' }, { href: '#contact', label: 'Contact' }, ] export default function SidebarMenu() { const [active, setActive] = useState('') const { lenis } = useScrollContext() useEffect(() => { const observers: IntersectionObserver[] = [] const onIntersect: IntersectionObserverCallback = (entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { setActive(`#${entry.target.id}`) } }) } const opts: IntersectionObserverInit = { rootMargin: '-30% 0px -60% 0px', threshold: 0.1 } const observer = new IntersectionObserver(onIntersect, opts) items.forEach((it) => { const id = it.href.replace('#', '') const el = document.getElementById(id) if (el) observer.observe(el) }) observers.push(observer) return () => { observers.forEach((o) => o.disconnect()) } }, []) return ( ) }