1- import React from "react" ;
1+ import React , { useState , useEffect , useRef } from "react" ;
22// import { Link } from "gatsby";
33
44import { Container , Row , Col } from "../../../reusecore/Layout" ;
@@ -22,6 +22,8 @@ import { getImage } from "gatsby-plugin-image";
2222import useHasMounted from "../../../utils/useHasMounted" ;
2323
2424const Banner1 = ( props ) => {
25+ const [ videoReady , setVideoReady ] = useState ( false ) ;
26+ const thumbnailRef = useRef ( null ) ;
2527
2628 const { heroImage } = useStaticQuery (
2729 graphql `
@@ -46,6 +48,37 @@ const Banner1 = (props) => {
4648
4749 const hasMounted = useHasMounted ( ) ;
4850
51+ // Set video as ready immediately after mount to avoid loading message
52+ useEffect ( ( ) => {
53+ if ( hasMounted ) {
54+ // Force the video to be marked as ready after a short delay
55+ // This ensures that even if events don't fire, the loading message will disappear
56+ const timer = setTimeout ( ( ) => {
57+ setVideoReady ( true ) ;
58+ } , 1000 ) ;
59+
60+ // Preload the thumbnail
61+ const img = new Image ( ) ;
62+ img . src = videoThumbnail ;
63+ img . onload = ( ) => {
64+ // Mark video as ready when thumbnail loads
65+ setVideoReady ( true ) ;
66+ } ;
67+
68+ return ( ) => clearTimeout ( timer ) ;
69+ }
70+ } , [ hasMounted ] ) ;
71+
72+ // Multiple handlers to ensure the video gets marked as ready
73+ const handleVideoReady = ( ) => {
74+ setVideoReady ( true ) ;
75+ } ;
76+
77+ const handleThumbnailClick = ( ) => {
78+ // Set ready when user clicks on thumbnail
79+ setVideoReady ( true ) ;
80+ } ;
81+
4982 return (
5083 < Banner1SectionWrapper { ...props } >
5184 < BGImg title = "heroImage" image = { pluginImage } >
@@ -61,10 +94,6 @@ const Banner1 = (props) => {
6194 < h2 >
6295 Collaborate to innovate
6396 </ h2 >
64- { /* <h1>Take the blinders off</h1>
65- <h2>
66- cloud native management
67- </h2> */ }
6897 </ SectionTitle >
6998 < span className = "vintage-box-container" >
7099 < VintageBox $right = { true } $vintageOne = { true } >
@@ -80,32 +109,45 @@ const Banner1 = (props) => {
80109 </ Col >
81110 { hasMounted && window . innerWidth > 760 && (
82111 < Col $sm = { 4 } $lg = { 6 } className = "section-title-wrapper video-col" >
83- < ReactPlayer
84- url = "https://youtu.be/034nVaQUyME?si=Yya8m6i7JUoSdZm4"
85- playing
86- controls
87- light = { videoThumbnail }
88- playIcon = {
89- < img
90- src = { playIcon }
91- className = "playBtn"
92- loading = "lazy"
93- alt = "Play"
94- role = "button"
95- aria-label = "Play"
96- style = { { fontSize : "24px" } }
97- />
98- }
99- width = "90%"
100- height = "30vw"
101- style = { { margin : "auto" } }
102- className = "embedVideo"
103- />
104- { /* <Link to="/cloud-native-management/kanvas">
105- <video autoPlay muted loop preload="metadata" className="kanvasVideo">
106- <source src={kanvasVideo} type="video/mp4"></source>
107- </video>
108- </Link> */ }
112+ < div
113+ className = { `video-wrapper ${ videoReady ? "video-loaded" : "" } ` }
114+ ref = { thumbnailRef }
115+ onClick = { handleThumbnailClick }
116+ >
117+ < ReactPlayer
118+ url = "https://youtu.be/034nVaQUyME?si=Yya8m6i7JUoSdZm4"
119+ playing
120+ controls
121+ light = { videoThumbnail }
122+ playIcon = {
123+ < img
124+ src = { playIcon }
125+ className = "playBtn"
126+ loading = "eager"
127+ alt = "Play"
128+ role = "button"
129+ aria-label = "Play"
130+ style = { { fontSize : "24px" } }
131+ />
132+ }
133+ width = "100%"
134+ height = "100%"
135+ className = "embedVideo"
136+ onReady = { handleVideoReady }
137+ onStart = { handleVideoReady }
138+ onPlay = { handleVideoReady }
139+ onBufferEnd = { handleVideoReady }
140+ onClickPreview = { handleVideoReady }
141+ config = { {
142+ youtube : {
143+ playerVars : {
144+ rel : 0 ,
145+ modestbranding : 1 ,
146+ }
147+ }
148+ } }
149+ />
150+ </ div >
109151 </ Col >
110152 ) }
111153 </ Row >
0 commit comments