diff --git a/frontend/src/apis/queries/main/useFetchMainLive.ts b/frontend/src/apis/queries/main/useFetchMainLive.ts index e7ec23c8..466da53c 100644 --- a/frontend/src/apis/queries/main/useFetchMainLive.ts +++ b/frontend/src/apis/queries/main/useFetchMainLive.ts @@ -7,6 +7,6 @@ export const useMainLive = () => { return useSuspenseQuery({ queryKey: ['mainLive'], queryFn: fetchMainLive, - refetchOnWindowFocus: false, + refetchOnWindowFocus: false }); }; diff --git a/frontend/src/components/main/LiveVideoCard.tsx b/frontend/src/components/main/LiveVideoCard.tsx index ca8908d4..d55f0461 100644 --- a/frontend/src/components/main/LiveVideoCard.tsx +++ b/frontend/src/components/main/LiveVideoCard.tsx @@ -1,5 +1,4 @@ import { useNavigate } from 'react-router-dom'; -import { useEffect, useState, useRef } from 'react'; import styled from 'styled-components'; import sampleProfile from '@assets/sample_profile.png'; @@ -7,7 +6,7 @@ import ShowInfoBadge from '@common/ShowInfoBadge'; import { ASSETS } from '@constants/assets'; import { RecentLive } from '@type/live'; import { LiveBadge, LiveViewCountBadge } from './ThumbnailBadge'; -import usePlayer from '@hooks/usePlayer'; +import { useVideoPreview } from '@hooks/useVideoPreview'; interface LiveVideoCardProps { videoData: RecentLive; @@ -15,71 +14,32 @@ interface LiveVideoCardProps { const LiveVideoCard = ({ videoData }: LiveVideoCardProps) => { const navigate = useNavigate(); - const [isHovered, setIsHovered] = useState(false); - const hoverTimeoutRef = useRef(null); - const thumbnailRef = useRef(null); - - const { concurrentUserCount, category, channel, tags, defaultThumbnailImageUrl, liveId, liveImageUrl, liveTitle, streamUrl } = - videoData; - - const videoRef = usePlayer(streamUrl); - - useEffect(() => { - const video = videoRef.current; - if (!video) return; - - const resetVideo = () => { - video.pause(); - video.currentTime = 0; - }; - - const playVideo = () => { - video.currentTime = 0; - video.play(); - }; - - const clearHoverTimeout = () => { - if (hoverTimeoutRef.current) { - clearTimeout(hoverTimeoutRef.current); - hoverTimeoutRef.current = null; - } - }; - - if (isHovered) { - hoverTimeoutRef.current = setTimeout(playVideo, 500); - return; - } - - clearHoverTimeout(); - resetVideo(); - - return clearHoverTimeout; - }, [isHovered]); - const handleLiveClick = () => { - navigate(`/live/${liveId}`); - }; + const { + concurrentUserCount, + category, + channel, + tags, + defaultThumbnailImageUrl, + liveId, + liveImageUrl, + liveTitle, + streamUrl + } = videoData; - const handleMouseEnter = () => { - setIsHovered(true); - }; + const { isHovered, isVideoLoaded, videoRef, handleMouseEnter, handleMouseLeave } = useVideoPreview(streamUrl); - const handleMouseLeave = () => { - setIsHovered(false); + const handleLiveClick = () => { + navigate(`/live/${liveId}`); }; return ( - - -