diff --git a/src/app/(home)/page.tsx b/src/app/(home)/page.tsx index 2941589..338c39f 100644 --- a/src/app/(home)/page.tsx +++ b/src/app/(home)/page.tsx @@ -2,7 +2,7 @@ import MorphText from "@/components/Morph"; import { Card } from "fumadocs-ui/components/card"; -import { useEffect, useState } from "react"; +import { useEffect, useRef, useState } from "react"; export const mistShowcase = [ { @@ -84,25 +84,64 @@ fn main() { }, ]; +// Sub-component to handle individual section observation +function ShowSection({ + show, + setActiveCode, +}: { + show: { title: string; description: string; code: string }; + setActiveCode: (v: string) => void; +}) { + const ref = useRef(null); + + useEffect(() => { + const observer = new IntersectionObserver( + ([entry]) => { + if (entry.isIntersecting) { + setActiveCode(show.code); + } + }, + { threshold: 0.5 }, + ); + + if (ref.current) observer.observe(ref.current); + return () => observer.disconnect(); + }, [show.code, setActiveCode]); + + return ( +
+

+ {show.title} +

+

{show.description}

+
+ ); +} + export default function HomePage() { + const [currentText, setCurrentText] = useState(mistShowcase[0]?.code || ""); + return (
{mistShowcase.map((show) => ( -
-

- {show.title} -

-

{show.description}

-
+ show={show} + setActiveCode={setCurrentText} + /> ))}
- + + + + +
);