import "./index.css" import { useEffect, useRef, useState } from "react" import { SectionNav } from "./components/SectionNav" import { Header } from "./components/sections/Header" import { Work } from "./components/sections/Work" import { Connect } from "./components/sections/Connect" import { GuestbookPage } from "./components/sections/GuestbookPage" import { sections } from "./data/portfolio" export function App() { const [activeSection, setActiveSection] = useState("") const [currentPath, setCurrentPath] = useState(window.location.pathname) const sectionsRef = useRef<(HTMLElement | null)[]>([]) // Handle SPA navigation useEffect(() => { const handlePopState = () => setCurrentPath(window.location.pathname) window.addEventListener('popstate', handlePopState) return () => window.removeEventListener('popstate', handlePopState) }, []) useEffect(() => { if (currentPath === '/guestbook') return // Skip observer on guestbook page const observer = new IntersectionObserver( (entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { entry.target.classList.add("animate-fade-in-up") setActiveSection(entry.target.id) } }) }, { threshold: 0.1, rootMargin: "0px 0px -5% 0px" }, ) sectionsRef.current.forEach((section) => { if (section) observer.observe(section) }) return () => observer.disconnect() }, [currentPath]) // Guestbook page if (currentPath === '/guestbook') { return (
) } return (
(sectionsRef.current[0] = el)} onGuestbookClick={() => { window.history.pushState({}, '', '/guestbook') setCurrentPath('/guestbook') }} />
(sectionsRef.current[1] = el)} /> (sectionsRef.current[2] = el)} />
) } export default App