From 706e53e5bc06ed0af95547d7d4bb18f7b209a392 Mon Sep 17 00:00:00 2001 From: Jakub Barczewski Date: Thu, 29 Aug 2024 17:19:08 +0200 Subject: [PATCH] chore: make video play on hover --- .../components/popupGallery/popupGallery.tsx | 71 +++++++++++++------ 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/apps/frontend/src/modules/common/components/popupGallery/popupGallery.tsx b/apps/frontend/src/modules/common/components/popupGallery/popupGallery.tsx index ec39d9f..73f1e0f 100644 --- a/apps/frontend/src/modules/common/components/popupGallery/popupGallery.tsx +++ b/apps/frontend/src/modules/common/components/popupGallery/popupGallery.tsx @@ -1,6 +1,6 @@ import { ArrowLeftIcon, ArrowRightIcon } from '@heroicons/react/24/solid'; import { Eye } from 'lucide-react'; -import { type ReactNode, useDeferredValue, useEffect, useMemo, useState } from 'react'; +import { type FC, type ReactNode, useDeferredValue, useEffect, useMemo, useRef, useState } from 'react'; import { Dialog, DialogContent, DialogTitle, DialogTrigger } from '../../../../../@/components/ui/dialog'; @@ -42,6 +42,52 @@ interface MediaProps { alt: string; } +interface MiniatureVideoProps { + previewVideoSrc: string | undefined; + onClick: () => void; +} + +const MiniatureVideo: FC = ({ previewVideoSrc, onClick }) => { + const videoRef = useRef(); + + const eyeRef = useRef(); + + useEffect(() => { + if (!videoRef.current || !eyeRef.current) { + return; + } + + eyeRef.current.onmouseover = async (): Promise => videoRef.current?.play(); + + eyeRef.current.onmouseleave = async (): Promise => videoRef.current?.pause(); + }); + + return ( +
+ +
+ +
+
+ ); +}; + export const Media = ({ alt, hasNext, @@ -82,25 +128,10 @@ export const Media = ({
{isVideoFile && ( -
- -
- -
-
+ )} {!isVideoFile && (