Skip to content

Commit

Permalink
feat: video active
Browse files Browse the repository at this point in the history
  • Loading branch information
2paperstar committed Feb 15, 2024
1 parent 8e2e56e commit f922392
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/pages/Videos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,19 +35,21 @@ export default function Videos() {
navigate(`/review/${data.data.list[0].id}`);
}, [data, id, navigate]);

const [activeIndex, setActiveIndex] = useState(0);

return (
<div className="flex flex-col h-screen">
<Header back review white text=" " fixed />
<Swiper
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) => (
<SwiperSlide key={review.id}>
<div className="h-full w-full">
<Video {...review} />
<Video {...review} active={activeIndex === index} />
</div>
</SwiperSlide>
))}
Expand Down
14 changes: 12 additions & 2 deletions src/pages/component/Video.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<HTMLVideoElement>(null);

const handleVideoClick = () => {
Expand All @@ -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 (
<div
className="w-full h-custom overflow-hidden relative bg-black"
Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default {
},
backgroundImage: {
'gradient-video':
'linear-gradient(to top,rgba(0,0,0,.4) 0,rgba(0,0,0,0) 160px),linear-gradient(to bottom,rgba(0,0,0,.4) 0,rgba(0,0,0,0) 96px)',
'linear-gradient(to top,rgba(0,0,0,.8) 120px,rgba(0,0,0,0) 260px),linear-gradient(to bottom,rgba(0,0,0,.4) 0,rgba(0,0,0,0) 96px)',
},
height: {
custom: 'calc(100vh - 60px)',
Expand Down

0 comments on commit f922392

Please sign in to comment.