diff --git a/src/pages/Videos.tsx b/src/pages/Videos.tsx index 02faaa5..cbd7ebf 100644 --- a/src/pages/Videos.tsx +++ b/src/pages/Videos.tsx @@ -6,7 +6,7 @@ import Video from './component/Video'; import { useNavigate, useParams } from 'react-router-dom'; import { useQuery } from '@tanstack/react-query'; import api from '../api'; -import { useEffect } from 'react'; +import { useEffect, useState } from 'react'; // type VideosProps = { // type: string; // profileImg: string; @@ -35,6 +35,8 @@ export default function Videos() { navigate(`/review/${data.data.list[0].id}`); }, [data, id, navigate]); + const [activeIndex, setActiveIndex] = useState(0); + return (
@@ -42,12 +44,12 @@ export default function Videos() { className="w-full h-full flex-1 bg-black" direction="vertical" slidesPerView={1} - onSlideChange={(d) => console.log(JSON.stringify(d))} + onSlideChange={(swiper) => setActiveIndex(swiper.activeIndex)} > - {data?.data.list.map((review) => ( + {data?.data.list.map((review, index) => (
-
))} diff --git a/src/pages/component/Video.tsx b/src/pages/component/Video.tsx index 32c0a80..79f96a5 100644 --- a/src/pages/component/Video.tsx +++ b/src/pages/component/Video.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; import Menu from './Menu'; import Grade from './Grade'; @@ -10,7 +10,7 @@ type VideoProps = { grade?: string; }; -const Video = ({ user, place, tags, stars, likes }: VideoProps) => { +const Video = ({ user, place, tags, stars, likes, active }: VideoProps) => { const videoEl = React.useRef(null); const handleVideoClick = () => { @@ -23,6 +23,16 @@ const Video = ({ user, place, tags, stars, likes }: VideoProps) => { } }; + useEffect(() => { + if (videoEl.current) { + if (active) { + videoEl.current.play(); + } else { + videoEl.current.pause(); + } + } + }, [active]); + return (