diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c9d04a1..9609c33 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,9 +4,8 @@ - - - + + diff --git a/components/HorizontalShowcase.tsx b/components/HorizontalShowcase.tsx index f7eb127..045f563 100644 --- a/components/HorizontalShowcase.tsx +++ b/components/HorizontalShowcase.tsx @@ -1,13 +1,10 @@ 'use client'; -import {useEffect, useRef, useState} from 'react'; -import Link from 'next/link'; +import {useEffect, useRef} from 'react'; import {gsap} from 'gsap'; import {ScrollTrigger} from 'gsap/ScrollTrigger'; import VendingCard from './VendingCard'; -import {showcaseVideoSrc} from '@/data/content'; import {featuredMachines} from '@/data/products'; -import {commerceCopy} from '@/data/commerce'; import {useLanguage} from '@/app/context/LanguageContext'; gsap.registerPlugin(ScrollTrigger); @@ -15,35 +12,21 @@ gsap.registerPlugin(ScrollTrigger); export default function HorizontalShowcase() { const sectionRef = useRef(null); const trackRef = useRef(null); - const videoRef = useRef(null); - const {t, locale} = useLanguage(); - const copy = commerceCopy[locale]; - const [videoAvailable, setVideoAvailable] = useState(true); + const backgroundRef = useRef(null); + const {t} = useLanguage(); useEffect(() => { const ctx = gsap.context(() => { const track = trackRef.current; const section = sectionRef.current; + const background = backgroundRef.current; if (!track || !section) return; const scrollDistance = () => Math.max(track.scrollWidth - window.innerWidth, 0); - let animationFrameId: number | null = null; - let latestProgress = 0; - - const syncVideo = (progress: number) => { - latestProgress = progress; - if (animationFrameId !== null) return; - - animationFrameId = window.requestAnimationFrame(() => { - const video = videoRef.current; - if (video && Number.isFinite(video.duration) && video.duration > 0) { - video.currentTime = latestProgress * video.duration; - } - animationFrameId = null; - }); - }; + const backgroundColors = ['#062522', '#0b3d38', '#123d67', '#45235e', '#4a2c18']; + const colorAtProgress = (progress: number) => gsap.utils.interpolate(backgroundColors, progress); const horizontalTween = gsap.to(track, { x: () => -scrollDistance(), @@ -55,12 +38,16 @@ export default function HorizontalShowcase() { scrub: 1, pin: true, invalidateOnRefresh: true, - onUpdate: self => syncVideo(self.progress), + onUpdate: self => { + if (!background) return; + + background.style.backgroundColor = colorAtProgress(self.progress); + background.style.backgroundPosition = `${self.progress * 100}% ${50 + self.progress * 30}%`; + }, }, }); return () => { - if (animationFrameId !== null) window.cancelAnimationFrame(animationFrameId); horizontalTween.scrollTrigger?.kill(); horizontalTween.kill(); }; @@ -71,18 +58,16 @@ export default function HorizontalShowcase() { return ( - - {videoAvailable && ( - setVideoAvailable(false)} - /> - )} + - - - {copy.featuredProducts} - - {copy.allProducts} - - - - {featuredMachines(t.machines).map(machine => (