From f806e4021f6ba464483da6c2f07c90e8d4c0bb54 Mon Sep 17 00:00:00 2001 From: David Mzareulyan Date: Sat, 15 Feb 2025 16:10:24 +0300 Subject: [PATCH] Don't play video on hover on non-hoverable devices --- src/components/post/attachments/visual/attachment.jsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/post/attachments/visual/attachment.jsx b/src/components/post/attachments/visual/attachment.jsx index a368686b..5f4679c8 100644 --- a/src/components/post/attachments/visual/attachment.jsx +++ b/src/components/post/attachments/visual/attachment.jsx @@ -44,11 +44,15 @@ export function VisualAttachment({ const pixRatio = usePixelRatio(); const handleMouseEnter = useEvent((e) => { - e.target.play(); + if (window.matchMedia?.('(hover: hover)').matches) { + e.target.play(); + } }); const handleMouseLeave = useEvent((e) => { - e.target.pause(); - e.target.currentTime = 0; + if (window.matchMedia?.('(hover: hover)').matches) { + e.target.pause(); + e.target.currentTime = 0; + } }); const [currentTime, setCurrentTime] = useState(0); const handleTimeUpdate = useEvent((e) => setCurrentTime(Math.floor(e.target.currentTime)));