From 7cb31a893a227105e59e072e2ac8c56a3b21f2cc Mon Sep 17 00:00:00 2001 From: Ebony Louis <55366651+EbonyLouis@users.noreply.github.com> Date: Mon, 3 Feb 2025 17:37:04 -0500 Subject: [PATCH] add video to homepage (#1050) --- .../src/components/HomepageFeatures/index.tsx | 121 +++++++++++------- 1 file changed, 76 insertions(+), 45 deletions(-) diff --git a/documentation/src/components/HomepageFeatures/index.tsx b/documentation/src/components/HomepageFeatures/index.tsx index 1c921504..544b6aa6 100644 --- a/documentation/src/components/HomepageFeatures/index.tsx +++ b/documentation/src/components/HomepageFeatures/index.tsx @@ -1,4 +1,5 @@ import type { ReactNode } from "react"; +import { useEffect, useRef, useState } from "react"; import clsx from "clsx"; import Heading from "@theme/Heading"; import styles from "./styles.module.css"; @@ -164,35 +165,42 @@ function Quote({ name, github, role, testimonial }: FeatureQuote) { } export default function HomepageFeatures(): ReactNode { + const videoRef = useRef(null); + const [videoLoaded, setVideoLoaded] = useState(false); + + useEffect(() => { + const observer = new IntersectionObserver( + (entries) => { + entries.forEach((entry) => { + if (entry.isIntersecting && !videoLoaded) { + setVideoLoaded(true); // Load video only when it first appears + } + }); + }, + { threshold: 0.5 } + ); + + if (videoRef.current) { + observer.observe(videoRef.current); + } + + return () => { + if (videoRef.current) { + observer.unobserve(videoRef.current); + } + }; + }, [videoLoaded]); + return (
-
@@ -200,28 +208,51 @@ export default function HomepageFeatures(): ReactNode { ))} - {/* inline styles in the interest of time */} -
-

- Loved by engineers -

-
+ {/* YouTube Video Section */} +
+

+ Meet Codename Goose +

+
+
+ +
+
+
+ + {/* Testimonials Section */} +
+

Loved by engineers

+
{FeatureQuotes.map((props, idx) => ( ))}