diff --git a/public/images/hero-palm-gradient-1600.webp b/public/images/hero-palm-gradient-1600.webp index 555d336f8..3113eff70 100644 Binary files a/public/images/hero-palm-gradient-1600.webp and b/public/images/hero-palm-gradient-1600.webp differ diff --git a/public/images/hero-palm-gradient-2400.webp b/public/images/hero-palm-gradient-2400.webp index 374765ad8..22e50ef5f 100644 Binary files a/public/images/hero-palm-gradient-2400.webp and b/public/images/hero-palm-gradient-2400.webp differ diff --git a/public/images/hero-palm-gradient-960.webp b/public/images/hero-palm-gradient-960.webp index f913c19d4..b0affad1c 100644 Binary files a/public/images/hero-palm-gradient-960.webp and b/public/images/hero-palm-gradient-960.webp differ diff --git a/public/images/hero-palm-gradient.jpg b/public/images/hero-palm-gradient.jpg index 3e955fe5e..4d121100c 100644 Binary files a/public/images/hero-palm-gradient.jpg and b/public/images/hero-palm-gradient.jpg differ diff --git a/src/components/home/HeroPalmMedia.tsx b/src/components/home/HeroPalmMedia.tsx index f3e3f1889..21c67c41d 100644 --- a/src/components/home/HeroPalmMedia.tsx +++ b/src/components/home/HeroPalmMedia.tsx @@ -4,11 +4,11 @@ import { Squircle } from '~/components/Squircle' export function HeroPalmMedia() { const videoRef = React.useRef(null) - const [hasVideoSource, setHasVideoSource] = React.useState(false) const [isVideoReady, setIsVideoReady] = React.useState(false) const [isPlaying, setIsPlaying] = React.useState(false) const playVideo = React.useCallback((video: HTMLVideoElement) => { + if (video.networkState === HTMLMediaElement.NETWORK_NO_SOURCE) video.load() const promise = video.play() if (promise !== undefined) { promise @@ -24,44 +24,28 @@ export function HeroPalmMedia() { }, []) React.useEffect(() => { + const video = videoRef.current + if (!video) return const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)') - if (!reducedMotion.matches) { - setHasVideoSource(true) - } - const pauseForReducedMotion = () => { - if (reducedMotion.matches) videoRef.current?.pause() + if (reducedMotion.matches) video.pause() } pauseForReducedMotion() + setIsPlaying(!video.paused) + setIsVideoReady(video.readyState >= HTMLMediaElement.HAVE_FUTURE_DATA) reducedMotion.addEventListener('change', pauseForReducedMotion) return () => reducedMotion.removeEventListener('change', pauseForReducedMotion) }, []) - React.useEffect(() => { - if ( - !hasVideoSource || - window.matchMedia('(prefers-reduced-motion: reduce)').matches - ) { - return - } - - const video = videoRef.current - if (video) playVideo(video) - }, [hasVideoSource, playVideo]) - const togglePlayback = () => { const video = videoRef.current if (!video) return if (video.paused) { - if (hasVideoSource) { - playVideo(video) - } else { - setHasVideoSource(true) - } + playVideo(video) } else { video.pause() } @@ -83,15 +67,14 @@ export function HeroPalmMedia() { src="/images/hero-palm-gradient.jpg" alt="" width={2400} - height={1600} + height={1058} loading="eager" fetchPriority="high" - className="h-full w-full object-cover object-center" + className={`relative z-10 h-full w-full object-cover object-center ${isVideoReady ? 'opacity-0 motion-reduce:opacity-100' : ''}`} />