diff --git a/frontend/src/pages/MainPage.tsx b/frontend/src/pages/MainPage.tsx index 8d194f7..f0cddba 100644 --- a/frontend/src/pages/MainPage.tsx +++ b/frontend/src/pages/MainPage.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, useRef } from 'react'; import { Typography, Box, @@ -56,6 +56,7 @@ const MainPage: React.FC = () => { const [feedRatings, setFeedRatings] = useState([]); const [loading, setLoading] = useState(true); const [activeIndex, setActiveIndex] = useState(0); + const timerRef = useRef | null>(null); const location = useLocation(); const query = new URLSearchParams(location.search).get('q') || ''; @@ -100,13 +101,20 @@ const MainPage: React.FC = () => { fetchData(); }, [query, isLoggedIn]); + const startTimer = () => { + if (timerRef.current) clearInterval(timerRef.current); + timerRef.current = setInterval(() => { + setActiveIndex(prev => (prev + 1) % topFlavors.length); + }, 6000); + }; + // Auto-rotate useEffect(() => { if (topFlavors.length > 0 && !query) { - const timer = setInterval(() => { - setActiveIndex(prev => (prev + 1) % topFlavors.length); - }, 6000); - return () => clearInterval(timer); + startTimer(); + return () => { + if (timerRef.current) clearInterval(timerRef.current); + }; } }, [topFlavors, query]); @@ -114,8 +122,14 @@ const MainPage: React.FC = () => { if (loading) return ; - const handlePrev = () => setActiveIndex(prev => (prev - 1 + topFlavors.length) % topFlavors.length); - const handleNext = () => setActiveIndex(prev => (prev + 1) % topFlavors.length); + const handlePrev = () => { + setActiveIndex(prev => (prev - 1 + topFlavors.length) % topFlavors.length); + startTimer(); + }; + const handleNext = () => { + setActiveIndex(prev => (prev + 1) % topFlavors.length); + startTimer(); + }; // --- SEARCH VIEW --- if (query) { @@ -338,25 +352,27 @@ const MainPage: React.FC = () => { - + + { {/* Recent Reviews - SIDE BY SIDE */} {recentReviews.length > 0 && ( - + {t('home.communityVoice')} - - {recentReviews.slice(0, 5).map(review => ( + + {recentReviews.map(review => (